开发者

QT/QML:How to show a message when the model has no data

开发者 https://www.devze.com 2023-03-13 01:45 出处:网络
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

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
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消