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

QQuickWidget Beginner-Problem

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 4.1k Views 2 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by A Former User
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • Andy314A Offline
        Andy314A Offline
        Andy314
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Andy314A 1 Reply Last reply
          0
          • SGaistS SGaist

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

            Are you using any layout manager ?

            Andy314A Offline
            Andy314A Offline
            Andy314
            wrote on last edited by Andy314
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #6

              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

              Andy314A 1 Reply Last reply
              0
              • SGaistS 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

                Andy314A Offline
                Andy314A Offline
                Andy314
                wrote on last edited by Andy314
                #7

                @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
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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
                  1
                  • SGaistS SGaist

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

                    C Offline
                    C Offline
                    cheezus
                    wrote on last edited by
                    #9

                    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
                    0

                    • Login

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