qt - 将我自己的 QML 按钮插入 GridLayout
问题描述
我是 Qt 的新手,想在 GridLayout 中有一些按钮(在单独的 .qml 文件中使用 Rectangle 制作......)。不幸的是,它似乎没有将按钮定位到不同的单元格。一切都在第一行/列。是否有必要的 ID 变量,如数组?还是 QML 动态对象?这里是按钮:
Item {
property string textOnButton: "Test"
property int w: 130
property int h: 100
Rectangle{
id: emptyRectangle
width: parent.w
height: parent.h
Text {
text: parent.parent.textOnButton + parent.index
anchors.horizontalCenter: parent.parent.horizontalCenter
topPadding: 6
font.pixelSize: 30
}
}
}
而这里的 GridLayout 应该在其中放置 Item 几次:
GridLayout{
id:grid1
rows: 3
Layout.margins: 20
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
columnSpacing: 10
rowSpacing: 10
EmptyButton{
id: eins
textOnButton: "HELP"
}
EmptyButton{
id: zwei
textOnButton: "HELP"
}
}
稍后我想在按钮上使用不同的颜色/文本并切换不同的灯光。谢谢你的帮助!!
解决方案
您需要设置 GridLayout 和所有其他项目的宽度和高度
GridLayout{
width: 500
height: 500
id:grid1
rows: 3
Layout.margins: 20
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
columnSpacing: 10
rowSpacing: 10
EmptyButton{
id: eins
textOnButton: "HELP"
}
EmptyButton{
id: zwei
textOnButton: "HELP"
}
}
推荐阅读
- javascript - React Router - Uncaught SyntaxError: Unexpected token < 刷新带有参数的 URL 时
- django - 如何使用当前用户作为 QuerySet 属性中的方法参数
- themes - 在 BigCommerce/Stencil 中上传和引用自定义图像
- python - 如何在 Python 中跟踪局部变量的值?
- javascript - jquery DataTables 父行和子行作为一条记录而不是两条记录发布到服务器
- jmx - 按名称堆叠/重叠指标
- r - R使用dplyr创建或修改数据框
- vba - Autofit.rowheight 取决于该行的每个单元格中的文本(字符串)
- kernel - 线程进程隔离容器
- c - 从数组中删除结构