You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

QML工具栏中两个复选框重叠,如何设置位置使其并排显示?

Qt ToolBar 中让两个CheckBox并排显示的解决办法

当然可以,给你两种实用的解决办法:

  • 方法一:用Row布局包裹CheckBox
    ToolBar本身没有内置横向排列逻辑,直接放置两个CheckBox会让它们都占满ToolBar空间,导致重叠。用Row组件包裹后,就能让控件自动横向并排:
header : ToolBar {
    Row {
        spacing: 10 // 可选,设置两个复选框的间距
        CheckBox {
           id: autoLoadButtonTB
           checked: true
           text: qsTr("Auto &Load")
           action: autoLoadAction
           mnemonicParsing: true // 开启后&后的字母会显示下划线,解决你的TODO问题
        }
        CheckBox {
           id: autoSaveButtonTB
           checked: true
           text: qsTr("&Auto Save")
           action: autoSaveAction
           mnemonicParsing: true
        }
    }
}
  • 方法二:用ToolButton实现复选功能(更贴合ToolBar设计)
    ToolBar更适配ToolButton组件,将其设置为checkable就能实现复选效果,且ToolBar会自动帮你完成横向排列:
header : ToolBar {
    ToolButton {
        checkable: true
        checked: true
        text: qsTr("Auto &Load")
        action: autoLoadAction
        mnemonicParsing: true
    }
    ToolButton {
        checkable: true
        checked: true
        text: qsTr("&Auto Save")
        action: autoSaveAction
        mnemonicParsing: true
    }
}

内容的提问来源于stack exchange,提问作者Pietro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 12:27:04