Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QQuickWidget Beginner-Problem

    General and Desktop
    3
    9
    2929
    Loading More Posts
    • 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.
    • Andy314
      Andy314 last edited by A Former User

      I have a QQuickWidget filled with a qml file.
      When this wigdet is unbound show() opens a new windows and I can see my listentries and scroll it,
      but when I put the widget on a QDialog is see only the first list entry and I cannot scroll the list. The count text show the correct size.
      Why that?

      import QtQuick 2.0
      
      Rectangle {
          anchors.fill: parent
      
         ListModel {
              id: nameModel
              ListElement { name: "Alice" }
              ListElement { name: "Bob" }
              ListElement { name: "Jane" }
              ListElement { name: "Harry" }
              ListElement { name: "Wendy" }
              ListElement { name: "Alice" }
              ListElement { name: "Bob" }
              ListElement { name: "Jane" }
              ListElement { name: "Harry" }
              ListElement { name: "Wendy" }
              ListElement { name: "Alice" }
              ListElement { name: "Bob" }
              ListElement { name: "Jane" }
              ListElement { name: "Harry" }
              ListElement { name: "Wendy" }
              ListElement { name: "Alice" }
              ListElement { name: "Bob" }
              ListElement { name: "Jane" }
              ListElement { name: "Harry" }
              ListElement { name: "Wendy" }
          }
          ListView
          {
              width: 180; height: 200
              anchors.fill: parent
              model: nameModel
              delegate: Text
              {
                  font.pixelSize: 20
                  text: name + ": "
              }
          }
          Text
          {
              id: textCount
              x: 8
              y: 300
              text: nameModel.count
              font.bold: true
              font.pixelSize: 23
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        How are you putting that widget in your QDialog ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • Andy314
          Andy314 last edited by

          Simple tag and drop from the widget palette onto the dialog or what was your question ?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Ok, that was the first step to identify your setup.

            Are you using any layout manager ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            Andy314 1 Reply Last reply Reply Quote 0
            • Andy314
              Andy314 @SGaist last edited by Andy314

              @SGaist
              I gave the dialog a vertical layout. At top I have a promoted frame, second element is the QickWidget.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by SGaist

                Modifying slightly your QML:

                import QtQuick 2.0
                
                Rectangle {
                    width: 180; height: 200
                    color: "blue"
                
                   ListModel {
                        id: nameModel
                        ListElement { name: "Alice" }
                        ListElement { name: "Bob" }
                        ListElement { name: "Jane" }
                        ListElement { name: "Harry" }
                        ListElement { name: "Wendy" }
                        ListElement { name: "Alice" }
                        ListElement { name: "Bob" }
                        ListElement { name: "Jane" }
                        ListElement { name: "Harry" }
                        ListElement { name: "Wendy" }
                        ListElement { name: "Alice" }
                        ListElement { name: "Bob" }
                        ListElement { name: "Jane" }
                        ListElement { name: "Harry" }
                        ListElement { name: "Wendy" }
                        ListElement { name: "Alice" }
                        ListElement { name: "Bob" }
                        ListElement { name: "Jane" }
                        ListElement { name: "Harry" }
                        ListElement { name: "Wendy" }
                    }
                    ListView
                    {
                        anchors.fill: parent
                        model: nameModel
                        delegate: Text
                        {
                            font.pixelSize: 20
                            text: name + ": "
                        }
                    }
                    Text
                    {
                        id: textCount
                        x: 8
                        y: 300
                        text: nameModel.count
                        font.bold: true
                        font.pixelSize: 23
                    }
                }
                

                and using this small main to have several widgets:

                int main(int argc, char *argv[])
                {
                QApplication app(argc, argv);
                QQuickWidget *widget = new QQuickWidget;
                    widget->setSource(QUrl::fromLocalFile("test.qml"));
                    widget->setMinimumSize(QSize(200, 200));
                    QWidget secondWidget;
                    QVBoxLayout *layout = new QVBoxLayout(&secondWidget);
                    layout->addWidget(new QLabel("Test me"));
                    layout->addWidget(widget);
                    secondWidget.show();
                    return app.exec();
                }
                

                Everything is working

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                Andy314 1 Reply Last reply Reply Quote 0
                • Andy314
                  Andy314 @SGaist last edited by Andy314

                  @SGaist thank you for your detailed help.

                  I found the problem: "fill-parent" of the root object.
                  If I give the rect a red color the full area is filled with red. Only the list doesnt work!
                  The strange thing is, that it works when I open the the pure widget.
                  Maybe it has something to do with inintilizing (sizing, in dialog invisible for the first time, order, etc.)

                  When must I initialize the QQickWidget. Constructor of the dialog - or later when it is visible?.

                  Rectangle {
                   //   anchors.fill: parent               ---- Problem
                  
                     ListModel {
                          id: nameModel
                          ListElement { name: "Alice" }
                  
                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    Technically, the Rectangle is the root of your QML so i'd say that it basically has no parent

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    C 1 Reply Last reply Reply Quote 1
                    • C
                      cheezus @SGaist last edited by

                      Just wanted to add a general comment here: anchor.fill: parent was the issue for me. As @SGaist says, there is no parent. Would be nice to have a proper error message but c'est la vie.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post