Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Cant' resize QQuickWidget that is child of QMainWindow
betty_crokker last edited by
I am creating a Qt5 mobile application that uses Qml for most of its UI, but then I need to use some native iOS controls so I also need to be able to use some QWidgets. Given those parameters, it seems like my only option is to create a Qt Widgets application and then use a QQuickWidget for my Qml.
When I create a brand new Qt Widgets application, it gives me a few files, including a mainwindow.ui with an annoying centralWidget that won't go away and I can't replace with anything else. So fine, I think, I will make my QQuickWidget a child of the centralWidget.
But of course that isn't enough, because the QQuickWidget doesn't know he should expand to fill his parent, the centralWidget. Qt Designer even gives me a little red-slash-circle on the centralWidget to let me know there's no layout happening. No worries.
For some reason right-clicking on "centralWidget" in the Object/Class table gives you completely different options from right-clicking on the central widget in the designer window. Not sure why that is, but OK. Right-click on the central widget in the designer window, tell it to do a horizontal layout. Now the Object/Class table is happy (no red-slash-circle).
But when I run the application, my QQuickWidget always has size zero (0x0). I put debugging statements into MainWindow::resizeEvent() that verifies that my centralWidget has a reasonable size (slightly smaller than my MainWindow, no doubt for the toolbar) but the quickWidget size is zero.
I've tried various sizePolicy options for my QQuickWidget (Ignored, MinimumExpanding, Expanding), it doesn't make any difference. I tried changing the layoutSizeConstraint of the horizontalLayout sitting inside my centralWidget, no difference.
For some reason my centralWidget seems to have its own Layout, named verticalLayout. I set its layoutSizeConstraint to SetMaximumSize too, no difference.
What's the magic? How can I get a Qt Widgets application that has a QQuickWindow as its main window, where that QQuickWindow fills the application?