Solved Simple QQuickWidget example doesn't fill rect?
-
The following example doesn't show the
Rectangle
. Maybe because the root object is not properly resized with the parent despiteQQuickWidget.SizeRootObjectToView
being set? Same results (none)QQuickWidget
is the parent or if theQWidget
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) }
-
Hi,
Might be a silly question but are you sure the qml file is found ?
-
@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.
-
@patrickkidd said in Simple QQuickWidget example doesn't work?:
anchors.fill: parent
A parent
Item
does not exist. Remove this line. -
@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!