Qt QML上下文菜单大小已调整为其内容

Qt QML上下文菜单大小已调整为其内容,qt,qml,qtquickcontrols2,Qt,Qml,Qtquickcontrols2,我对Qt快速大小策略、宽度、隐式宽度、边界等感到困惑。我有菜单,当单击圆形按钮时会弹出该菜单。问题是菜单太大了。请看附带的屏幕截图。项目应将对齐设置为右侧: 我可以通过在图标标签上设置Layout.fillWidth:true来实现这一点: 不过,菜单太大了,我有固定大小的300,但我想根据内容调整它的大小。此外,即使将间距、填充和边距设置为0,项目之间的空间也太大。我用的是深色的材料。以下是代码: Menu { id: roundButtonMenu modal: true

我对Qt快速大小策略、宽度、隐式宽度、边界等感到困惑。我有
菜单
,当单击圆形按钮时会弹出该菜单。问题是菜单太大了。请看附带的屏幕截图。项目应将对齐设置为右侧:

我可以通过在图标
标签上设置
Layout.fillWidth:true
来实现这一点:

不过,菜单太大了,我有固定大小的
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()
    }
}

我将尝试添加到背景和行布局:
width:childrenRect.width:childrenRect.height
并删除布局。填充属性。没有帮助。将其添加到菜单的矩形会导致菜单根本不可见,并且还会使用
QML RowLayout:Binding循环将其添加到属性“width”的RowLayout结果中
我将尝试添加到您的背景和行布局:
宽度:childrenRect.width高度:childrenRect.height
并删除布局。填充属性。没有帮助。将其添加到菜单的矩形会导致菜单根本不可见,并且还会将其添加到RowLayout结果中,并使用
QML RowLayout:Binding循环检测到属性“width”