【发布时间】:2018-01-21 22:14:25
【问题描述】:
我有一个 4 列的表格,其中之一是文本。当您更改列的宽度时,内部文本的宽度也会发生变化。在某些情况下,文本的宽度变得相当小并且文本开始增加其高度(文本换行)。如何增加此文本所在行的高度?
这是一个带有文本的列
TableViewColumn {
id: fullNameColumn
property int minColWidth: 175
property int maxColWidth: 500
role: "fullName"
title: "ФИО"
width: 360
property string imageSource : ""
onWidthChanged: {
if (width < minColWidth)
width = minColWidth
}
delegate: Rectangle{
id: rowCellContentFullName
color: "transparent"
Text {
property int maxColWidth: 400
id: labelFullName
objectName: "labelFullName"
font.pixelSize: 13
wrapMode: Text.Wrap
anchors.leftMargin: 38
anchors.left: parent.left
horizontalAlignment: styleData.textAlignment
anchors.verticalCenter: parent.verticalCenter
visible: parent.visible
width: parent.width - this.anchors.leftMargin * 2
text: styleData.value !== undefined ? styleData.value : ""
color: "#474747"
renderType: Text.NativeRendering
}
}
这是 rowDelegate
property Component rowDelegate: Rectangle {
id: rowDel
objectName: "RowDelegate"
height: parent.parent.children[1].children[2].children[0].children[0].height < 50 ? 50 : parent.parent.children[1].children[2].children[0].children[0].height
property color selectedColor: styleData.hasActiveFocus ? primaryColor : secondaryColor
property bool selectionMaskVisible
property bool selected: false
}
在 rowDelegate 中,我用可怕的表情绑定高度,但它有效。仅适用于第 3 列(其中 FullName)。如果我将此列拖到另一个空间中,我的代码将不起作用。
如果没有这个可怕的表达式,我可以在 TableView QML 中更改行高吗? Mb 你知道解决这个问题的方法吗?
【问题讨论】:
-
仔细查看 onWidthChanged 以及还有哪些可以修复/改进的地方?
标签: qt qml row-height