Reputation: 33423
Window {
id: uninstallWindow
width: 640
height: 480
property variant pluginData;
TableView {
id:_pluginTable
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 43
anchors.top: parent.top
anchors.topMargin: 0
model: pluginData
itemDelegate: Text {
text: modelData
font.pixelSize: 24
}
TableViewColumn {
}
}
}
I change the font size of the items in the table because they were too small by default. This simply caused them to get clipped by the non-changing row size.
I've tried:
Setting a rowDelegate
object (but this causes loss of all other styling info that is there by default like background, selection color, etc and I don't know how to specify it otherwise)
Setting a custom model object based on QAbstractListModel/QAbstractTableModel (for some reason only known to Qt, the "data" function was never ever called...)
Setting a custom item delegate (it seems that the height is no longer controlled from this object, though)
How do I get the rows to change their size?
Upvotes: 4
Views: 7472
Reputation: 759
A custom row height can be achieved using the rowDelegate
, but this discards the default style, but it can be restored using the SystemPalette
.
rowDelegate: Rectangle {
height: 30
SystemPalette {
id: myPalette;
colorGroup: SystemPalette.Active
}
color: {
var baseColor = styleData.alternate?myPalette.alternateBase:myPalette.base
return styleData.selected?myPalette.highlight:baseColor
}
}
This restores the default background color of the rows (including alternating the row colors when desired) and the color of the selected rows, which seems to be all that is needed.
Upvotes: 8
Reputation: 21
In Qt 5.10:
rowDelegate: Item { height: 30 }
I do the actual styling (fonts/colors) in itemDelegate
(and in headerDelegate
), and provide content by TableViewColumn
s (with and without delegates of their own).
Upvotes: 2
Reputation: 357
To change the row height, you need to use rowDelegate
. For example:
rowDelegate: Rectangle{
width: childrenRect.width
height: 40
}
To change TableView's height, you can use Layout.preferredHeight
. For example:
Layout.preferredHeight: 300
Upvotes: 2