QT/QML:How to show a message when the model has no data
I've implement a simple Model View app, when there is no data in the model, the 开发者_运维知识库ListView is just a blank form. I want to know how to show a convenient message,telling that the model has no data. Thank you.
Overlay a listview and a text element on top of each other. Set visibilty to true or false depending on model.count
ListView{
visible : if(model.count > 0) true;else false;
}
Text{
visible : if(model.count > 0) false;else true;
}
At least with QtQuick2 you can do something like this:
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
}
}
精彩评论