gpt4 book ai didi

qt - 在行布局中垂直对齐项目

转载 作者:行者123 更新时间:2023-12-04 02:01:21 26 4
gpt4 key购买 nike

我正在使用 Rowlayout 使用 qml 创建一行按钮,但在对齐按钮时遇到了问题。然后我想在垂直和水平方向居中对齐。

我试过如下:

RowLayout
{
anchors.fill: parent
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

ToolButton {
//anchors.verticalCenter: parent.verticalCenter
//anchors.horizontalCenter: parent.horizontalCenter
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
source: "../images/search.png"
}
}

ToolButton {
//anchors.verticalCenter: parent.verticalCenter
//anchors.horizontalCenter: parent.horizontalCenter
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
source: "../images/search.png"
}
}
}

结果如下图所示:

enter image description here

如何使图像从中心向外对齐?

最佳答案

你的意思是这样的:

image

添加 Layout.alignment: Qt.AlignRight | Qt.AlignVCenterToolButtons

RowLayout
{
anchors.fill: parent
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

ToolButton {
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
//anchors.verticalCenter: parent.verticalCenter
//anchors.horizontalCenter: parent.horizontalCenter
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
source: "search.png"
}
}

ToolButton {
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
//anchors.verticalCenter: parent.verticalCenter
//anchors.horizontalCenter: parent.horizontalCenter
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
source: "search.png"
}
}
}

关于qt - 在行布局中垂直对齐项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47040602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com