TableView与QML不正确的大小
问题描述:
我想创建一个带有QML的TableView,我有一个复选框,一个图像和一个文本字段。表的列定义如下:TableView与QML不正确的大小
// TableViewCheckBoxColumn.qml
TableViewColumn {
title: ""
role: "check"
delegate: CheckBox {
anchors.fill: parent
checked: styleData.value
}
}
//TableViewImageColumn.qml
TableViewColumn {
title: ""
role: "thumbnail"
delegate: Image {
anchors.fill: parent
source: styleData.value
width: 30
height: 30
}
}
现在数据模型和表本身如下被定义为QML组件:
Item {
ListModel {
id: sourceModel
ListElement {
check: false
thumbnail: "file:///Users/xargon/alignment.png"
length: "10:22"
}
}
// Table view
TableView {
anchors.centerIn: parent
alternatingRowColors: false
TableViewCheckBoxColumn {
id: checkedColumn
}
TableViewImageColumn {
id: thumbColumn
}
TableViewColumn {
id: lengthColumn
role: "length"
title: "Length"
}
model: sourceModel
}
}
现在,这被嵌入在ColumnLayout和StackView如:
ColumnLayout {
anchors.fill: parent
MyTable {
id: reviewScreen
Layout.fillWidth: true
}
StackView {
id: options
Layout.fillHeight: true
Layout.fillWidth: true
initialItem: reviewScreen
}
}
现在我期待的表格填写父控件的整个宽度,我也期待中的图像被绘制成30×30的图像,但我看到的是附上屏幕截图,其中水平滚动条在控件之间移动,桌子很小,图像也很扭曲。
答
是的,只有你需要声明HEIGH和重量每TableViewColumn,例如:
TableViewColumn { id: lengthColumn; role: "length"; title: "Length"; height: parent.height/8; width:parent.width*0.25}
你需要指定的宽度和高度的每个元素。 – DenimPowell