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 QML not rendered correctly
Forum Updated to NodeBB v4.3 + New Features

QQuickWidget QML not rendered correctly

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 1.8k 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.
  • N Offline
    N Offline
    nwoki
    wrote on last edited by
    #1

    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;
        }
    }
    
    
    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

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

      157

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        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
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        N 1 Reply Last reply
        3
        • dheerendraD dheerendra

          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
          
          }
          

          }

          N Offline
          N Offline
          nwoki
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nwoki
            wrote on last edited by
            #5

            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

            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