- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经基于类似于此的 QAbstractListModel 创建了一个 ListView 模型 example .问题是我的 ListView 不显示所有行,而只显示最初可见的行。所以当我向下滚动(或轻弹)时,只有黑色空间。 ListView 有 count == 0 但它应该有 count == 10,因为我已经添加了 10 个元素。
我的类包含更新模型 rowCount 的必要方法
// needed as implementation of virtual method
int rowCount(const QModelIndex & parent) const {
return standings.size();
}
int rowCount() {
return standings.size();
}
void addStanding(const Standing &st) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
qDebug() << "row cnt: " << rowCount();
standings << st;
endInsertRows();
}
我还更新了 ListView 模型
rootContext = (QDeclarativeContext*)(viewer->rootContext());
rootContext->setContextProperty("myModel", &sm);
QML代码
ListView {
id: raceList
objectName: "standingList"
y: header.height
width: parent.width
height: parent.height - header.height
clip: true
model: myModel
delegate: rowComp
}
Component {
id: rowComp
SessionRowDelegate { }
}
我还想提一下,这适用于静态模型。如何让 ListView 始终显示所有项目,而不仅仅是在对用户可见时显示?
session 行委托(delegate)
Rectangle {
id: rowbg
width: parent.width
height: 34 * (1 + (parent.width - 360) * 0.002)
// contains other elements with height not exceeding rowbg's height
// ...
}
最佳答案
有点晚了(4 年!),但在卡住了几天后我发现了与这个问题相关的东西!问题主要在于 ListView 处理模型的奇怪方式。
在我自己的模型中覆盖 rowCount 方法后,我遇到了您提到的确切问题。有趣的是,他们从来没有被调用过。 ListView 实际上从不调用获取 rowCount,而是查询 cacheBuffer 大小的数量(在我的系统上默认为 512),这就是为什么它不会注意到项目是否超过 cacheBuffer 大小或它使用的默认值,它只会在滚动到末尾时注意到。
虽然这会阐明一些其他人的问题,但这不是您问题的解决方案。在你的情况下,如果项目不是那么多,我建议调整 ListView cacheBuffer 的大小,并根据需要增加它。请记住,如果您的元素过多,可能会导致巨大的性能损失。
关于c++ - QML ListView 计数为零,只有一些行可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13748161/
如果下一个元素的宽度超过指定布局的宽度,是否有 QML 布局或某些配置会自动将 QML 项目包装到下一行? 当我使用 QML GridLayout ,项目刚好离开窗口的边缘并被剪裁: GridLayo
如果下一个元素的宽度超过指定布局的宽度,是否有 QML 布局或某些配置会自动将 QML 项目包装到下一行? 当我使用 QML GridLayout ,项目刚好离开窗口的边缘并被剪裁: GridLayo
如何在 qml 文件之间发送变量或信号? http://i.stack.imgur.com/MChCG.png Mainwindow -> 创建组件Item2.qml MainWindow -> 创建
我正在做一些事情,我有一个名为“FloatingMenu”的类(它应该在 C++ 中管理菜单)及其在文件 FloatingMenu.qml 中用于 GUI 的 QML alter-ego。我有一个文件
我正在尝试做一些看似简单的事情,但失败了:定义一个简单的内联文本格式组件,然后用不同的文本多次实例化它。这是代码 Item { . . . Component { id: favButtonL
我可以在页面中使用 InvokeActionItem 轻松共享项目,但我需要能够在 ListView 项目中调用它。我设法触发了一个调用,但我不知道如何在触发它时添加数据。我不断收到错误消息 Invo
我如何在 QML 中检测 Window {} 之外的点击? Rectangle { id: topLevel height: 400; width: 400 Window {
我试过 : var child = grid.children[slot1]; grid.children[slot1] = grid.children[slot2]; grid.children[s
例如,我希望创建一个包含 100 个文本编辑器的 qml 窗口,如何在循环中创建它?那可能吗? 最佳答案 循环是命令式代码,所以它不是 QML,而是 Javascript 或 C++。所以当然,你可以
这是我的 QML 文件,其中包含一个文本组件: import QtQuick 2.0 Item { id: idItmWrapText Text { id: idTxt
我正在寻找一种方法来显示一个文本提示,说明预期的输入作为对用户的建议。以谷歌搜索栏为例: 是否有我缺少的属性,或者这是必须通过脚本来实现的? 最佳答案 Qt Quick 输入项上不存在该属性。您可以为
为 qml 项设置背景的最简单方法是让子矩形的 anchor 完全填满父项: Item { width: 320 height: 240 Rectangle {
我想将属性动态添加到 QML 元素: Item { id: dynamicProperty; property int first; Component.onCompleted: { /*
我用 PySide 和 QML 编写了某种安装程序。按照设计,它必须是多页的。而且我想将要从 QML 表单调用的插槽划分为不同的对象(理想情况下,划分为模块,但据我了解,带有插槽的对象必须继承 QOb
QML 中有没有办法用 opacity: 0 创建一个矩形?仍然有可见的边界?如果没有,有关如何解决它的任何建议? 谢谢 最佳答案 不,不透明度适用于项目的完整视觉方面(并且不透明度:0 使项目完全不
属性变体 a:{}似乎不起作用。 a 最终未定义,而不是一个空字典。 我对 Javascript 不是很有经验...初始化属性以保存空字典的正确方法是什么? 以下 qml 在控制台上打印“qrc:/m
我在 SO 上查看了大量关于 QML 内容边距的问题,但所有答案都指向缺少 spacing: 0 属性。我已经完成了所有这些,但仍然有一些我无法消除的奇怪空间。任何人都可以解释为什么这个 QML 代码
我有一个用于样式定义的 QML 单例,定义如下: pragma Singleton import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQu
这是以下代码的结果: 主.qml import QtQuick 2.8 Item { Reusable { index: 1234 // reusable with
属性变体 a:{}似乎不起作用。 a 最终未定义,而不是一个空字典。 我对 Javascript 不是很有经验...初始化属性以保存空字典的正确方法是什么? 以下 qml 在控制台上打印“qrc:/m
我是一名优秀的程序员,十分优秀!