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. Simple QQuickWidget example doesn't fill rect?
Forum Updated to NodeBB v4.3 + New Features

Simple QQuickWidget example doesn't fill rect?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 800 Views 3 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by patrickkidd
    #1

    The following example doesn't show the Rectangle. Maybe because the root object is not properly resized with the parent despite QQuickWidget.SizeRootObjectToView being set? Same results (none) QQuickWidget is the parent or if the QWidget subclass is the parent.

    I imagine I'm missing something simple here...

    import sys
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    from PyQt5.QtQml import *
    from PyQt5.QtQuick import *
    from PyQt5.QtQuickWidgets import *
    
    class Parent(QWidget):
    
        def __init__(self):
            super().__init__()
    
            self.qml = QQuickWidget()
            self.qml.setResizeMode(QQuickWidget.SizeRootObjectToView)
            self.qml.setSource(QUrl.fromLocalFile('./main.qml'))
            self.qml.show()
            Layout = QVBoxLayout(self)
            Layout.addWidget(self.qml)
            Layout.setContentsMargins(0, 0, 0, 0)
    
    
    app = QApplication(sys.argv)
    
    if True:
        parent = QQuickWidget()
        parent.setResizeMode(QQuickWidget.SizeRootObjectToView)
        parent.setSource(QUrl.fromLocalFile('./main.qml'))
        parent.resize(400, 600)
        parent.show()
    else:
        parent = Parent()
        parent.resize(800, 600)
        parent.show()
    
    app.exec()
    
    import QtQuick 2.10
    import QtQuick.Controls 2.3
    
    
        Rectangle {
            color: '#aa0000ff'
            anchors.fill: parent
            onHeightChanged: print('***', width, height)
        }
    

    https://alaskafamilysystems.com/

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

      Hi,

      Might be a silly question but are you sure the qml file is found ?

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

      P 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Might be a silly question but are you sure the qml file is found ?

        P Offline
        P Offline
        patrickkidd
        wrote on last edited by
        #3

        @SGaist said in Simple QQuickWidget example doesn't work?:

        Hi,

        Might be a silly question but are you sure the qml file is found ?

        Yep. I wrote in a timer and timer is running and printing to the console.

        https://alaskafamilysystems.com/

        1 Reply Last reply
        0
        • P patrickkidd

          The following example doesn't show the Rectangle. Maybe because the root object is not properly resized with the parent despite QQuickWidget.SizeRootObjectToView being set? Same results (none) QQuickWidget is the parent or if the QWidget subclass is the parent.

          I imagine I'm missing something simple here...

          import sys
          from PyQt5.QtCore import *
          from PyQt5.QtGui import *
          from PyQt5.QtWidgets import *
          from PyQt5.QtQml import *
          from PyQt5.QtQuick import *
          from PyQt5.QtQuickWidgets import *
          
          class Parent(QWidget):
          
              def __init__(self):
                  super().__init__()
          
                  self.qml = QQuickWidget()
                  self.qml.setResizeMode(QQuickWidget.SizeRootObjectToView)
                  self.qml.setSource(QUrl.fromLocalFile('./main.qml'))
                  self.qml.show()
                  Layout = QVBoxLayout(self)
                  Layout.addWidget(self.qml)
                  Layout.setContentsMargins(0, 0, 0, 0)
          
          
          app = QApplication(sys.argv)
          
          if True:
              parent = QQuickWidget()
              parent.setResizeMode(QQuickWidget.SizeRootObjectToView)
              parent.setSource(QUrl.fromLocalFile('./main.qml'))
              parent.resize(400, 600)
              parent.show()
          else:
              parent = Parent()
              parent.resize(800, 600)
              parent.show()
          
          app.exec()
          
          import QtQuick 2.10
          import QtQuick.Controls 2.3
          
          
              Rectangle {
                  color: '#aa0000ff'
                  anchors.fill: parent
                  onHeightChanged: print('***', width, height)
              }
          
          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @patrickkidd said in Simple QQuickWidget example doesn't work?:

          anchors.fill: parent

          A parent Item does not exist. Remove this line.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          P 1 Reply Last reply
          0
          • JKSHJ JKSH

            @patrickkidd said in Simple QQuickWidget example doesn't work?:

            anchors.fill: parent

            A parent Item does not exist. Remove this line.

            P Offline
            P Offline
            patrickkidd
            wrote on last edited by
            #5

            @JKSH said in Simple QQuickWidget example doesn't work?:

            @patrickkidd said in Simple QQuickWidget example doesn't work?:

            anchors.fill: parent

            A parent Item does not exist. Remove this line.

            It sure does. Wow, intuitively that line would be required. Thanks!

            https://alaskafamilysystems.com/

            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