我试图将 GridLayout 包装在 Item 中,并将 GridLayout 的 data 属性公开为该项目的默认属性。但这会导致两个问题。
退出应用程序时发生崩溃。
- 这实际上可能是 Qt 本身的一个错误,它也可能已经修复,如果没有,我会在修复 2 后报告它。我目前只能使用 Qt 5.7.0 MSVC2015 32.bit 在 Windows 7 上进行测试。
如何使用附加的 Layout 属性?看下面的例子,它会导致错误:
Non-existent attached object
在线的
"Layout.alignment: Qt.AlignBottom | Qt.AlignRight".
例子:
//MyCustomLayout.qml
import QtQuick 2.7
import QtQuick.Layouts 1.3
Item {
default property alias data: layout.data
//Some other QML components not to be within GridView here.
GridLayout {
id: layout
anchors.fill: parent
}
//Some other QML components not to be within GridView here.
}
//main.qml
import QtQuick.Controls 2.0
ApplicationWindow {
id: root
visible: true
height: 1024
width: 768
MyCustomLayout {
anchors.fill: parent
Button {
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
}
}
}