Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QFileDialog alternative that uses default file dialog defined by OS?

Tags:

c++

qt

I tried using a QFileDialog in a program of mine, but I prefer the default file dialog that is used by the host's OS. In my case, since I use Windows 7, it should look like this:

Windows' file open dialog

Is there a way to make Qt use the default file dialog that is used by the host's OS?


My code:

QFileDialog saveDialog(this);
saveDialog.setAcceptMode(QFileDialog::AcceptSave);

if (!saveDialog.exec())
    return;
like image 234
Pieter Avatar asked Oct 20 '25 10:10

Pieter


1 Answers

Use the static functions for it and it will work.

QString filename = QFileDialog::getOpenFileName(this, ... vars);

It will use the native dialogs for OSX and Windows, but if you don't use one of the static functions to show it, it will use the QT one.

It was written in the docs for those different static functions.

http://doc.qt.io/qt-4.8/qfiledialog.html

like image 135
Paul Avatar answered Oct 23 '25 00:10

Paul