【问题标题】:How to elide Text item in a layout without a fixed size?如何在没有固定大小的布局中省略文本项?
【发布时间】:2018-09-03 12:11:24
【问题描述】:

根据Text.elide的文档

只有在设置了明确的宽度时,文本才会消失。

但是如果我希望我的 Text 项目占用布局中的所有可用空间并删除不适合的内容怎么办?

例如,具有固定宽度项目(图标、按钮...)和一些文本的布局:

RowLayout
{
    id: _layout
    anchors.fill: parent

    Rectangle {
        color: "lightblue"
        height: 20
        width: 20
    }
    Text {
        text: "long words long words long words long words long words long words long words long words long words long words "
        elide: Text.ElideRight
    }
    Rectangle {
        color: "lightblue"
        height: 20
        width: 20
    }
}

如果窗口/容器太小,此代码将被截断,并隐藏文本后面的项目(也不会像省略文本一样显示...)。

【问题讨论】:

  • 你可以只使用锚点吗?或使用Layout.fillWidth: true

标签: qt qml


【解决方案1】:

您必须指定布局应如何限制宽度,例如与:

Text {
    text: "long words long words long words long words long words long words long words long words long words long words "
    elide: Text.ElideRight

    Layout.fillWidth: true
}

见:http://doc.qt.io/qt-5/qml-qtquick-layouts-layout.html#fillWidth-attached-prop

【讨论】:

  • 我必须在 Text 项目上指定这个。
猜你喜欢
  • 2012-10-28
  • 1970-01-01
  • 2012-11-22
  • 2019-09-20
  • 2017-06-19
  • 1970-01-01
  • 2023-03-18
  • 2013-08-10
  • 1970-01-01
相关资源
最近更新 更多