在QML中,我想为一行网格制作一个可操作的范围。这样做的原因是我希望能够将网格内的一行标记为删除,而不会触发整个网格的重绘,因为完全重绘看起来非常笨拙并导致GUI在重新处理所有行时暂停:
我提出了一种机制,但它似乎非常hacky:
GridLayout {
columns: 4;
// header
Text { Layout.alignment: Qt.AlignCenter; text: 'Red'; }
Text { Layout.alignment: Qt.AlignCenter; text: 'Green'; }
Text { Layout.alignment: Qt.AlignCenter; text: 'Blue'; }
Text { Layout.alignment: Qt.AlignCenter; text: 'Remove?'; }
Repeater {
model: [
{r: '100', g: '40', b:'27'},
{r: '136', g: '63', b:'42'}
]
Repeater {
model: 4;
property var pt : modelData;
Loader {
Component {
id: _R;
Text {
text: pt.r;
font.strikeout: !!pt.marked_for_deletion;
}
}
Component {
id: _G;
Text {
text: pt.g;
font.strikeout: !!pt.marked_for_deletion;
}
}
Component {
id: _B;
Text {
text: pt.b;
font.strikeout: !!pt.marked_for_deletion;
}
}
Component {
id: _Del;
Button {
width: text_input.font.pointSize*2;
font.pointSize: text_input.font.pointSize*2;
text: pt.marked_for_deletion ? '↶' :'-';
onClicked: {
pt.marked_for_deletion = !pt.marked_for_deletion;
pt = pt;
}
}
}
sourceComponent: (
index === 0 ? _R :
(index === 1 ? _G :
(index === 2 ? _B :
_Del)));
}
}
}
}
如果没有嵌套在Repeater内的奇怪Loader
,有没有更好的方法呢? Repeater可以在没有封闭组件的情况下返回多个元素吗?我不能将Column
与嵌套的Row
组件一起使用,因为列不会像表格那样对齐。