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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.