gpt4 book ai didi

qt - 在 QML Text 元素中启用 "elide"属性,但在 GridLayout 中

转载 作者:行者123 更新时间:2023-12-03 02:19:24 31 4
gpt4 key购买 nike

我知道必须隐式设置“width”属性才能使elide正常工作。但是,我在布局中有一个 Text 元素。当文本太长时我想截断文本。当 Text 类型位于 GridLayout 中时,如何在 Text 类型中使用 elide

import QtQuick 2.5
import QtQuick.Layouts 1.1


Rectangle {
width: 100
height: 20

GridLayout {
clip: true
anchors.fill: parent

rows: 1

Text{
text: "veryverylooooooonnnnnnnnnnnggggggggggggggtext"
width: 50

elide: Text.ElideRight
}

}
}

最佳答案

width: 50 更改为 Layout.preferredWidth: 50

import QtQuick 2.5
import QtQuick.Layouts 1.1
Rectangle {
width: 100
height: 20
GridLayout {
clip: true
anchors.fill: parent
rows: 1
Text {
text: "veryverylooooooonnnnnnnnnnnggggggggggggggtext"
Layout.preferredWidth: 50
elide: Text.ElideRight
}
}
}

结果: enter image description here

关于qt - 在 QML Text 元素中启用 "elide"属性,但在 GridLayout 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39300239/

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