英文:
QML: two checkboxes in the same toolbar are overlapped - cannot set position
问题
我有一个工具栏,里面有两个复选框,它们已经正确生成,但我无法设置它们的位置,所以它们被放置在彼此上面。
header : ToolBar {
CheckBox {
id: autoLoadButtonTB
checked: true
text: qsTr("自动加载") //TODO 'L' 应该被下划线
action: autoLoadAction
}
CheckBox {
id: autoSaveButtonTB
checked: true
text: qsTr("自动保存") //TODO 'A' 应该被下划线
action: autoSaveAction
}
}
是否可能让它们并排放置?
英文:
I have a toolbar with two checkboxes, which are correctly generated, but I cannot set their position, and so they are placed one on top of the other.
header : ToolBar {
CheckBox {
id: autoLoadButtonTB
checked: true
text: qsTr("Auto &Load") //TODO 'L' should be underlined
action: autoLoadAction
}
CheckBox {
id: autoSaveButtonTB
checked: true
text: qsTr("&Auto Save") //TODO 'A' should be underlined
action: autoSaveAction
}
}
Is it possible to have them one next to the other?
答案1
得分: 2
Here is the translated content from your provided text:
如果您查看文档 https://doc.qt.io/qt-6/qml-qtquick-controls-toolbar.html,它演示了使用 ToolBar
和 RowLayout
的示例。如果我们将其应用到您的示例中,我们会得到:
header : ToolBar {
RowLayout {
CheckBox {
id: autoLoadButtonTB
checked: true
text: qsTr("自动加载") //TODO 'L' 应该被下划线
action: autoLoadAction
}
CheckBox {
id: autoSaveButtonTB
checked: true
text: qsTr("自动保存") //TODO 'A' 应该被下划线
action: autoSaveAction
}
}
}
此外,您可能考虑将 CheckBox
替换为 ToolButton
或 MenuItem
,并设置 checkable: true
。它们的功能与 CheckBox
类似,但它们的外观可能更符合 ToolBar
所需的一致性外观。
英文:
If you check the documentation https://doc.qt.io/qt-6/qml-qtquick-controls-toolbar.html, it demonstrates the ToolBar
with a RowLayout
. If we apply that to your example, we get:
header : ToolBar {
RowLayout {
CheckBox {
id: autoLoadButtonTB
checked: true
text: qsTr("Auto &Load") //TODO 'L' should be underlined
action: autoLoadAction
}
CheckBox {
id: autoSaveButtonTB
checked: true
text: qsTr("&Auto Save") //TODO 'A' should be underlined
action: autoSaveAction
}
}
}
Also, you may like to consider replacing CheckBox
with ToolButton
or MenuItem
with checkable: true
. They function similarly to a CheckBox
but, they're look may be more consistent with what's needed for ToolBar
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论