QML:同一工具栏中的两个复选框重叠 – 无法设置位置

huangapple go评论80阅读模式
英文:

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,它演示了使用 ToolBarRowLayout 的示例。如果我们将其应用到您的示例中,我们会得到:

    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 替换为 ToolButtonMenuItem,并设置 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.

huangapple
  • 本文由 发表于 2023年5月30日 06:03:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360545.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定