QQuickWidget Beginner-Problem



  • 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
        }
    }
    

  • Lifetime Qt Champion

    Hi,

    How are you putting that widget in your QDialog ?



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


  • Lifetime Qt Champion

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

    Are you using any layout manager ?



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


  • Lifetime Qt Champion

    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



  • @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" }
    

  • Lifetime Qt Champion

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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.