0

I want to open a QFileDialog over a QQuickItem.

 void
 MyCoolQQuickItem::loadFileDialog()
 {
   QString filename = QFileDialog::getOpenFileName(this, "Open a file", 
                      "C:\\path to my stuff\\", "*.*");
   if(filename.size()>0) {
     // load file and do stuff
   }
 }

My MyCoolQQuickItem is a Subclass of QQuickItem. And QFileDialog::getOpenFileName need a QWidget* as parent. If I pass a null_ptr instead, the dialog opens correctly as modal dialog. But after I close the dialog the wrong window gets the focus.

I tried to pass the window instead(this->window(), but I have a QQuickWindow, what also could not be parsed in a QWidget.

I could use the QML File-Dialog instead. http://qt-project.org/doc/qt-5/qml-qtquick-dialogs-filedialog.html

But I want to use a QFileDialog here. http://qt-project.org/doc/qt-5/qfiledialog.html

Any Idea how I can solve this?

Vasco Rinaldo
  • 171
  • 1
  • 6

1 Answers1

1

Just use the QML version, it is absolutely the same dialog you will get from the QWidget based dialog. The only thing you will gain from using a QWidget based dialog is you will make it backward and you will drag several MBs for the Qt5Widgets library.

Whatever you think you might be gaining from wanting to do that, it will not be worthy the effort to do it. The old QtQuick1 offered a proxy component to show widgets in QML, but this is not available with QtQuick2, because it has a different approach towards rendering.

dtech
  • 47,916
  • 17
  • 112
  • 190
  • Thanks for your answer, with saving space with not adding Qt5Widgets you have a good point. I just want to be able to use the good old dialogs and started adding this QFileDialog without thinking doing it in QML. I'll try it. – Vasco Rinaldo Nov 23 '14 at 22:13