我正在构建一个 Python + QtQuick 应用程序,它需要一个从QQuickPaintedItem 降级的类。我在管理已绘制项目的布局和大小时遇到了一些麻烦。
特别是,我有一个看起来像这样的应用程序
左侧有一组按钮,窗口右侧是一个加载程序(这是一个很好的理由,这只是演示问题的最小示例)。
主 qml 文件 ( main.qml) 如下所示:
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
ApplicationWindow {
id: mainWindow
visible: true
width: 720
height: 480
title: qsTr("QML Sampler")
onClosing: main.close_application()
RowLayout {
anchors.fill: parent
ColumnLayout {
id: sideBar
Layout.fillHeight: true
Layout.preferredWidth: 200
Layout.minimumWidth: 150
Layout.maximumWidth: 350
Button {
id: buttonScreen1
text: "Button 1"
Layout.fillWidth: true
}
Button {
id: buttonScreen2
text: "Button 2"
Layout.fillWidth: true
}
}
Loader {
id: contentAreaLoader
Layout.fillHeight: true
Layout.preferredWidth: 520
Layout.minimumWidth: 300
source: 'loaded_content.qml'
}
}
}
加载的内容文件是实际包含自定义类的文件,如下所示 ( loaded_content.qml):
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import CustomPaintedItem 1.0
ColumnLayout {
anchors.fill: parent
Label {
text: "Here's a thing!"
}
CustomPaintedItem {
Layout.fillHeight: true
Layout.fillWidth: true
}
}
噜噜哒
相关分类