Unsolved Make QQuickWidget responsive to resizing
-
I have a MainWindow derived from QMainWindow and two widgets: one QQuickWidget that is showing content from a qml file and one QPrintPreviewWidget. I want to arrange them in such a way that both of them resize to fit the window when the window is expanded and I am unable to do that. When the window pops up, the two widgets are overlapping and when i keep increasing the size of the window, they keep increasing only upto a point after which only the layout expands but the widgets don't expand anymore. Can someone point out what's missing? Here's my code:
main.cpp
#include <QtWidgets> #include <QtQuickWidgets/QQuickWidget> #include "preview.h" class QmlWidget : public QWidget { public: QmlWidget() { qml_widget = new QQuickWidget(QUrl("qrc:/main.qml"), this); qml_widget->setResizeMode(QQuickWidget::SizeRootObjectToView); } private: QQuickWidget *qml_widget; }; class MainWindow : public QMainWindow { public: MainWindow() { QHBoxLayout *layout = new QHBoxLayout(); QmlWidget *qml_widget = new QmlWidget(); qml_widget->resize(640,480); PrintPreviewWidget *preview_widget = new PrintPreviewWidget(); preview_widget->resize(360,480); layout->addWidget(qml_widget); layout->addWidget(preview_widget); setCentralWidget(new QWidget()); centralWidget()->setLayout(layout); } }; int main(int argc, char** argv) { QApplication app(argc, argv); MainWindow window; window.show(); return app.exec(); }
main.qml
Rectangle { visible: true width: 640 height: 480 }
-
Difficult to anwser...
But you may notice the size policy first.