How to set QFileDialog's parent to a QQuickView - qt

The only window in my application is a QQuickView which is a subclass of QWindow, not of QWidget, so if I want to use a QFileDialog to give the user the option to save a file, I do not know how to set its parent to be the QQuickView. I know that the QFileDialog works without a parent, but if it does not have a parent, it is not centered over the QQuickView. This is not a big problem on its own, but on my OS (Ubuntu 13.10) a QFileDialog without a parent sometimes appears under the QQuickView window and the user sees only a “flashing” taskbar icon.
I use Qt 5.2. I initially tried to use the FileDialog type in the Qt Quick Dialogs module but it does not have some features I need (such as the defaultSuffix property).

Right, this is a serious problem of QML. You cannot utilize the QFileDialog because you don't have a QWidget app and FileDialog lacks some critical features.
See: FileDialog in QTQuick (QML): Save file under given name
At the moment we are using code from deep down in the Qt source code, which is not in the public API. It only requires a Window instead of a Widget to do modality right.
Maybe I can write a blog post about that over Christmas.

Related

qt virtual keyboard and non-modal dialog

Is it possible to make Qt Quick application to continue input, while TextField is in the non-modal Dialog, which parented to some of children of an ApplicationWindow and InputPanel is a footer of the window?
Currently on desktop (Ubuntu 16.04 w/ GNOME) Dialog is QDialog widget-based. And when I touch virtual keyboard the Dialog lost focus and virtual keyboard became inactive because of enabled property defined as follows:
footer: InputPanel {
enabled: Qt.inputMethod.visible
}
It is a circulus vituosus. Either I need a latest fallback from cite (the cite if for FileDialog, but it may still be actual for Dialog):
The implementation of FileDialog will be a platform file dialog if possible. If that isn't possible, then it will try to instantiate a QFileDialog. If that also isn't possible, then it will fall back to a QML implementation, DefaultFileDialog.qml. In that case you can customize the appearance by editing this file. DefaultFileDialog.qml contains a Rectangle to hold the dialog's contents, because certain embedded systems do not support multiple top-level windows. When the dialog becomes visible, it will automatically be wrapped in a Window if possible, or simply reparented on top of the main window if there can only be one window.
Or I need a way to touch virtual keyboard, but not lost focus from a Qt Quick Control.

QML Popups not working properly with C++ application

I have an application in Qt in which I can switch between c++ app and QML app (setting central widget to one or other).
The problem is that in order to work this, I had to change my main.qml from ApplicationWindow to Page and now Dialogs and all Popups in my QML app are not working properly (modality and focus is not working at all).
My code looks like that:
QQuickWidget *view = new QQuickWidget(this);
view->setSource(QUrl(QStringLiteral("qrc:/main.qml"))); //Page
MyCppApp *myCppApp = new MyCppApp (this); //QWidget
QStackedWidget *stackedWidget = new QStackedWidget;
stackedWidget->addWidget(view);
stackedWidget->addWidget(myCppApp);
stackedWidget->setCurrentIndex(1);
setCentralWidget(stackedWidget);
I know in Popup's documentation there is that "It can be used with Window or ApplicationWindow." but is there a way to get Popups in my QML work properly?
I am using Qt 5.8 and Qt Quick Controls 2.
For the modality you should not make the dialog window part of central widget in main window (otherwise it is modal relative to what?). Invoke it from main window. And to give it modal dialog looks and behavior you can apply window flags like that:
// this view is not a part of the app main window
view->setFlags(Qt::Dialog | Qt::WindowTitleHint |
Qt::WindowStaysOnTopHint | Qt::MSWindowsFixedSizeDialogHint);
Mind that Qt::MSWindowsFixedSizeDialogHint is of course applicable on Windows only. And for setting the focus:
// to set the edit focus such trick needed
QTimer::singleShot(0, view, SLOT(setFocus()));
I use that with QML widget container. Implementation details may differ. And no QML part visible. There you may need to take care of FocusScope then.

Parenting an object in PyQt causes the object to be owned by Qt instead of PyQt. What are the consequences?

In the QObject.__init__(self, Parent=None) documentation it states:
The parent argument, if not None, causes self to be owned by Qt instead of PyQt.
What does it mean to be owned by Qt instead of PyQt? Does this have effects on behavior that I should be aware of when developing a PyQt application?
Yes, It is. It have Effects to before create any object in PyQt application. If we set parent QWidget None, I can be tell this QWidget is top-level window. I will try explain;
"Parent Widget equivalent like frame of windows"
Parent Widget of QMainWindow is none. Then, owned by Qt instead of PyQt (or easy word root). Parent Widget of QWidget (in red) is QMainWindow, Then geometry reference by QMainWindow. Parent Widget of QPushButton is QWidget (Green), Then geometry reference by QWidget (Green). And all widget as same ...
So, QMainWindow have fully control widget in your child. For example, If self delete, All child will follow delete too. etc.
But, If we set Parent Widget of QWidget (in red) is None, that mean this QWidget like new window. Like this picture;
For now, we have 2 top-level window. But QWidget have independent with QMainWindow. If self delete, All child will follow delete too but not outside QMainWindow. Outside QWidget not delete. So, some application have create many widget, but it will has main widget in main menu to control child.
Not only frame of windows, It just Example & Comparison.
Regards,

Rendering QML over another window using QWidget

I am currently using QWidget to embed a window from another library (Panda3D). I've been trying to see if it was possible to add a QML-based interface to Panda3D by rendering a QQuickView over the QWidget containing Panda3D's window.
When I don't initialize Panda3D, I can see my QQuickView being properly rendered over the widget: but when I do reparent Panda3D's window to the widget, then the window is rendered over the QQuickView.
I'd like to know if what I'm trying to do is possible, and if yes, how would I do such a thing ?

Issue with full screen mode in qt5

I have an application in qml. I am using quickview and setting it as full screen. But when I try to open a .ui file(QWidget) from full screen mode it is going behind the mainwindow. this doesn't happen when I am not in full screen mode. I have tried setting flag (Qt::WindowStaysOnTopHint) but it doesn't work. I am using QT5 . Thanks for the help
QUiLoader loader;
QFile file("abc.ui");
file.open(QFile::ReadOnly);
QWidget * _parent = loader.load(&file);
file.close();
_parent->setParent(mainlayout);
_parent->setWindowFlags(Qt::Tool);
_parent->setWindowFlags(_parent->windowFlags() | Qt::WindowStaysOnTopHint)
In this the mainlayout is quickview
The widget parenting behavior in Qt differs between QDialog and QWidget. A QDialog is always a top-level widget (a window). I guess that your the object that your .ui file creates is not a QDialog. Please ensure that it is:
QWidget * _parent = loader.load(&file);
Q_ASSERT(qobject_cast<QDialog*>(_parent));
If this assert fails, then you need to change your .ui file's base class to be a dialog.
You should probably also activate and raise your dialog:
_parent->activateWindow();
_parent->raise();

Resources