qt - QML 上下文菜单大小根据其内容调整
问题描述
我对 Qt Quick 大小策略、宽度、隐式宽度、边界等感到困惑。Menu
单击圆形按钮时,我有哪个弹出窗口。问题是菜单太大了。看随附的屏幕截图。项目应将对齐设置为右:
我可以通过设置Layout.fillWidth: true
icon来做到这一点Label
:
但是,菜单太大了,我有固定的大小300
,但我想根据内容调整它的大小。此外,即使将间距、填充和边距设置为 0,项目之间的空间也会很大。我使用的是材质深色样式。这是代码:
Menu {
id: roundButtonMenu
modal: true
spacing: 0
padding: 0
margins: 0
Action { text: qsTr("File"); icon.name: FAIcons.faFile}
Action { text: qsTr("Folder"); icon.name: FAIcons.faFolderOpen}
Action { text: qsTr("Link"); icon.name: FAIcons.faLink}
delegate: MenuItem {
id: menuDelegate
spacing: 0
padding: 0
contentItem: RowLayout {
spacing: 0
Label {
id: mIcon
text: menuDelegate.icon.name
Layout.fillWidth: true
Layout.alignment: Qt.AlignRight
horizontalAlignment: Text.AlignRight
font.family: FALoader.icons
background: Rectangle {
color: "transparent"
border.color: "red"
}
}
Label {
id: mLabel
Layout.fillWidth: false
text: menuDelegate.text
Layout.alignment: Qt.AlignRight
background: Rectangle {
color: "transparent"
border.color: "red"
}
}
}
background: Rectangle {
color: "transparent"
}
}
background: Rectangle {
implicitWidth: 300
color: "transparent"
border.color: "#21be2b"
radius: 2
}
}
CPRoundButton {
id: btnAdd
iconfa: FAIcons.faPlus
anchors.right: parent.right
anchors.bottom: parent.bottom
onClicked: {
roundButtonMenu.x = 10
roundButtonMenu.y = 10
roundButtonMenu.open()
}
}
解决方案
推荐阅读
- python - 为什么不将此字符串解析为日期?
- android - Android 中的小写操作按钮(默认/非自定义)通知
- angular - Web 视图登录错误 - Mercadopago
- vba - VBA,代码在 excel 2010 中运行良好,在 2013 年运行缓慢且无响应错误
- python - 无法在 CNN 上执行回归
- python - 用空格字符替换序列的第一个
- bash - 递归运行 bash 脚本并对子目录中的所有文件执行操作
- node.js - Firestore 通过 gmail 而不是 sendgrid 发送邮件
- javascript - Firebase +节点JS同步错误?
- c - C AES不解密二进制文件