QML ToolButton 不调整大小

QML ToolButton not resizing

我不明白为什么我的 ToolButton 这么小。工具栏是顶部的橙色矩形。以下代码:

Item{

    ToolBar{
        id: toolbar
        width: parent.width
        height: scaleDP(0.29)
        anchors.top: parent.top

        background: Rectangle{
            color: "orange"
        }

        RowLayout{
            anchors.fill: parent


            ToolButton {
                id: buttonBack
                height: parent.height
                width: parent.height
                Image {
                    id: imageBack
                    source: "qrc:/assets/images/left-filled-black-50.png"
                    anchors.fill: parent
                    anchors.margins: 4
                }


            }

显示我的 ToolButton 太小了:

我可以更改图像的高度并使其变大,但随后它会超出 ToolButton。当我尝试调整 ToolButton 的高度时,没有任何反应

调查结果

看来问题出在 RowLayout 上。如果我将其更改为行或矩形,则图标会按预期调整大小。

RowLayout 使用其子项的 implicitHeight 和 implicitWidth,并忽略高度和宽度。对于一些简单的项目(例如矩形),设置它们的高度也会改变它们的隐含高度,但对于像 ToolButton 这样的 QuickControl 则不是这样。

RowLayout{
    height: 20
    width: parent.width
    // WON'T WORK
    ToolButton {
        id: buttonBack1
        height: parent.height
        width: parent.height
    }
    // OK
    ToolButton {
        id: buttonBack2
        Layout.preferredHeight: parent.height
        Layout.preferredWidth: parent.height
    }
    // OK TOO
    ToolButton {
        id: buttonBack3
        implicitHeight: parent.height
        implicitWidth: parent.height
    }
}

如果您还需要 RowLayout,您有两个选择: