Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQuickWidget size
Forum Updated to NodeBB v4.3 + New Features

QQuickWidget size

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I don't understand how to handle sizes of a QQuickWidget. For example I place it in a QTabWidget:

    QQuickWidget _formOverview;
    _formOverview.setSource(QUrl("qrc:/qml/main.qml"));
    _formOverview.setResizeMode(QQuickWidget::SizeRootObjectToView);
    _formOverview.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    ui->tabView->addTab(&_formOverview, tr("Overview"));
    

    main.qml file:

    import QtQuick 2.11
    
    Rectangle {
        anchors.fill: parent
        visible: true
        color: "blue"
    }
    

    but the size of the rectangle is 0,0.
    How to fill the whole area?

    J.HilkJ 1 Reply Last reply
    0
    • YunusY Offline
      YunusY Offline
      Yunus
      wrote on last edited by
      #2

      @Mark81 Hi. Did you try to add 'width and height' parameters to the rectangle?

      M 1 Reply Last reply
      0
      • M Mark81

        I don't understand how to handle sizes of a QQuickWidget. For example I place it in a QTabWidget:

        QQuickWidget _formOverview;
        _formOverview.setSource(QUrl("qrc:/qml/main.qml"));
        _formOverview.setResizeMode(QQuickWidget::SizeRootObjectToView);
        _formOverview.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        ui->tabView->addTab(&_formOverview, tr("Overview"));
        

        main.qml file:

        import QtQuick 2.11
        
        Rectangle {
            anchors.fill: parent
            visible: true
            color: "blue"
        }
        

        but the size of the rectangle is 0,0.
        How to fill the whole area?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Mark81

        try it without the anchors.fill: parent

        Usually, for me at least, the root item of a QQuickWidgets qml file does not have a size specified and matched the parent QQuickWidget automatically.

        If I remember correctly, that QQuickView doesn't do that and you would have to specify a size for the root element.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        M 1 Reply Last reply
        1
        • YunusY Yunus

          @Mark81 Hi. Did you try to add 'width and height' parameters to the rectangle?

          M Offline
          M Offline
          Mark81
          wrote on last edited by
          #4

          @Yunus said in QQuickWidget size:

          @Mark81 Hi. Did you try to add 'width and height' parameters to the rectangle?

          Of course it would work, but I don't want a fixed size! I want to fill the actual area of the parent.

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Mark81

            try it without the anchors.fill: parent

            Usually, for me at least, the root item of a QQuickWidgets qml file does not have a size specified and matched the parent QQuickWidget automatically.

            If I remember correctly, that QQuickView doesn't do that and you would have to specify a size for the root element.

            M Offline
            M Offline
            Mark81
            wrote on last edited by
            #5

            @J.Hilk said in QQuickWidget size:

            try it without the anchors.fill: parent

            Usually, for me at least, the root item of a QQuickWidgets qml file does not have a size specified and matched the parent QQuickWidget automatically.

            If I remember correctly, that QQuickView doesn't do that and you would have to specify a size for the root element.

            You're right. It works!
            I didn't find this information in the documentation, and it's not so intuitive!

            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