Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Make QQuickWidget responsive to resizing
Qt 6.11 is out! See what's new in the release blog

Make QQuickWidget responsive to resizing

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rithvikp
    wrote on last edited by
    #1

    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
    }
    
    1 Reply Last reply
    0
    • jiancaiyangJ Offline
      jiancaiyangJ Offline
      jiancaiyang
      wrote on last edited by
      #2

      Difficult to anwser...
      But you may notice the size policy first.

      我们自己的论坛:http://qtdream.com
      擅长三维角色仿真动画。

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved