我有以下代码显示一行按钮。 我希望按钮具有相同的宽度,但似乎无法到达那里。 有人知道怎么做吗?
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"
}
}
}
}
答案 0 :(得分:0)
这应该可以解决问题。确保RoundButton
未设置其width
和height
属性,但是使用implicitWidth
和implicitHeight
,因此使用大小的布局。
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"
}
}
}
}