我已经实现了一个简单的模型视图应用程序,当模型中没有数据时,ListView 只是一个空白表单。我想知道如何显示一个方便的消息,告诉模型没有数据。谢谢你。
问问题
3614 次
2 回答
2
至少使用 QtQuick2,您可以执行以下操作:
import QtQuick 2.9
import QtQuick.Controls 2.2
ListView {
model: ...
clip: true
Label {
anchors.fill: parent
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
visible: parent.count == 0
text: qsTr("Nothing to show yet!")
font.bold: true
}
}
于 2017-08-26T22:29:53.417 回答
1
将列表视图和文本元素叠加在一起。根据 model.count 将可见性设置为 true 或 false
ListView{
visible : if(model.count > 0) true;else false;
}
Text{
visible : if(model.count > 0) false;else true;
}
于 2011-06-14T12:46:59.570 回答