QML 应用程序中只有一行 ListView 填充,知道为什么吗?

发布于 2024-09-16 00:09:23 字数 947 浏览 1 评论 0原文

我正在尝试创建一个简单的 QML 应用程序,它将获取我的活跃国际象棋游戏的 RSS 提要并用它做一些事情。此时,我只是尝试使用提要内容填充列表视图,但即使提要中应该有 11 个项目,它也只显示一项。这是一个错误还是我没有得到正确的东西?

代码如下:


    import Qt 4.7
    import "content"

    Rectangle {
        id : window;
        width : 320
        height : 480

        XmlListModel {
            id : xmlModel

            source : "http://gameknot.com/rss.pl?n=kEzvYvEgfHoOmzQzQlY/5w5ITO5YDN"
            query : "/rss/channel/item"

            XmlRole { name: "title"; query: "title/string()"}
            XmlRole { name: "description"; query: "description/string()"}
        }

        Column
        {
            id : mainContainer

                ListView
                {

                    id : list
                    model : xmlModel
                    delegate : ListDelegate { }
                    //delegate: Text { text: title }
                }
        }
    }

委托应该没问题,因为我注释掉的简单委托也会发生同样的事情。

I'm trying to create a simple QML application that will get an RSS feed with my active chess games and do stuff with it. At this point I am just trying to populate a list view with the feed contents, but it only shows one item even when there should be 11 items in the feed. Is this a bug or am I not getting something right?

Here's the code:


    import Qt 4.7
    import "content"

    Rectangle {
        id : window;
        width : 320
        height : 480

        XmlListModel {
            id : xmlModel

            source : "http://gameknot.com/rss.pl?n=kEzvYvEgfHoOmzQzQlY/5w5ITO5YDN"
            query : "/rss/channel/item"

            XmlRole { name: "title"; query: "title/string()"}
            XmlRole { name: "description"; query: "description/string()"}
        }

        Column
        {
            id : mainContainer

                ListView
                {

                    id : list
                    model : xmlModel
                    delegate : ListDelegate { }
                    //delegate: Text { text: title }
                }
        }
    }

The delegate should be all right, because the same thing also happens with the simple delegate I have commented out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2024-09-23 00:09:23

你的模型和视图都很好,是你的布局错误。尝试将 anchors.fill:parent 添加到 mainContainer 中。这应该解决它:

Column
{
    anchors.fill: parent
    id : mainContainer

    ListView
    {
        width: parent.width
        height: parent.height

        id : list
        model : xmlModel
        delegate : ListDelegate { }
        //delegate: Text { text: title }
    }
}

Your model and view are fine, it's your layout that's wrong. Try adding anchors.fill: parent to mainContainer. That should fix it:

Column
{
    anchors.fill: parent
    id : mainContainer

    ListView
    {
        width: parent.width
        height: parent.height

        id : list
        model : xmlModel
        delegate : ListDelegate { }
        //delegate: Text { text: title }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文