如何使QML圆形按钮在行布局中具有相同的大小

时间:2019-01-29 16:41:15

标签: qml

我有以下代码显示一行按钮。 我希望按钮具有相同的宽度,但似乎无法到达那里。 有人知道怎么做吗?

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {

        RowLayout {
            id: rowLayout
            RoundButton {
                id: roundButton
                text: "Engage"
            }

            RoundButton {
                id: roundButton1
                text: "Disengage"
            }
         }
    }
}

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题。确保RoundButton 设置其widthheight属性,但是使用implicitWidthimplicitHeight,因此使用大小的布局。

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {

        RowLayout {
            id: rowLayout
            width: parent.width
            height: 300
            RoundButton {
                id: roundButton
                Layout.fillWidth: true
                text: "Engage"
            }

            RoundButton {
                id: roundButton1
                Layout.fillWidth: true
                text: "Disengage"
            }
        }
    }
}