QQuickWidget QML not rendered correctly



  • Hi all. I'm porting an old XP application to Qt5 using Widgets. I need to use a Switch element from QML so I have a QQuickWidget element for the purpose. Problem is that the switch is not rendered. What I get instead is a white space where the QML item is supposed to be. Any clues on why this happens?

    Here is the code for the QML component used.

    P.S - I use this component in two different places. On one place it's correctly rendered whilst on the other it is not.

    import QtQuick 2.0
    import QtQuick.Controls 1.4
    
    
    /**
     * !!!IMPORTANT!!!!
     *
     * this class signal "checked" is used by different C++ objects in the project. Careful when modding
     *
     */
    Item {
        id: root;
    
        signal checked(bool checked);
    
        // use this to get the system colours to use for the background so the switch doesn't stand out too much
        SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
    
        Rectangle {
            id: bg;
            color: myPalette.window;
            anchors.fill: parent;
        }
    
        Switch {
            id: stepLapSwitch;
    
            anchors {
                centerIn: root;
            }
    
            onClicked: {
                root.checked(stepLapSwitch.checked);
            }
        }
    
        function setChecked(checked) {
            stepLapSwitch.checked = checked;
        }
    }
    
    

  • Moderators

    @nwoki Can you post rest of the code which can reproduce the problem ?



  • Did you try something like this ? It works. We have used it.

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QQuickView view;
    view.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
    
    QMLWidget w;
    QWidget *w1 = QWidget::createWindowContainer(&view,&w);
    w1->setFixedSize(400,400);
    w.show();
    
    return app.exec();
    

    }

    QML code

    Rectangle {
    visible: true
    width: 640
    height: 480
    color : "green"

    Switch {
        anchors.centerIn: parent
    
    }
    

    }



  • @dheerendra Thanks! Specifying the width solved the issue. For some reason I didn't specify it on the second widget.



  • But I have anoter "QQuickWidget QML not rendered correctly" question.

    I have a tabbed widget with qquickwidgets in it. The first time the tab page with the QQuickWidgets is rendered, i can see the QML item. If then i switch to the next tab and back again, I end up with a white space.

    The QML file I'm using:

    import QtQuick 2.2
    import QtQuick.Extras 1.4
    
    Item {
        id: root;
    
        // use this to get the system colours to use for the background so the switch doesn't stand out too much
        SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
    
        width: 30;
        height: 30;
    
        Rectangle {
            id: bg;
            color: myPalette.window;
            anchors.fill: parent;
        }
    
        StatusIndicator {
            id: indicator;
            height: parent.height - 4;
            width: parent.width - 4;
            anchors.centerIn: parent;
            color: "green";
        }
    
        function setActive(active) {
            indicator.active = active;
        }
    }
    
    

    Any ideas why I get this behaviour?

    P.S - The QQuickWidget is layed out in a .ui form


Log in to reply
 

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