qabstractlistmodel

PyQT list view not responding to datachanged signal

♀尐吖头ヾ 提交于 2020-01-23 07:51:13
问题 I've been following some tutorials and trying to get a list model set up. My main window has two list views that are accessing the same model. When I update an item in one list, the other list doesn't update itself until it gets focus (I click on it). So it looks like the dataChanged signal isn't being emitted, but I can't work out how my code is different to any of the examples I'm basing it from. main.py class Main(QtWidgets.QMainWindow): def __init__(self, parent=None): super(Main, self)._

PyQT list view not responding to datachanged signal

流过昼夜 提交于 2020-01-23 07:51:10
问题 I've been following some tutorials and trying to get a list model set up. My main window has two list views that are accessing the same model. When I update an item in one list, the other list doesn't update itself until it gets focus (I click on it). So it looks like the dataChanged signal isn't being emitted, but I can't work out how my code is different to any of the examples I'm basing it from. main.py class Main(QtWidgets.QMainWindow): def __init__(self, parent=None): super(Main, self)._

How do you access the roles of the currentItem from a listview in QML?

断了今生、忘了曾经 提交于 2019-12-30 01:55:08
问题 I'm trying to access a role from a ListView in QML. Essentially, I have this in my QML: ListView { id: myId model: myModel delegate: Item { Text { text: model.text } Text { text: model.moreText } } } myModel is a QAbstractListModel implementation. The QML portion of this is a reusable component, so the model could have any number of different roles with various data types. What I would like to do is bind to the value of a given role of the currentItem property of the ListView. In other words,

how to insert/edit QAbstractListModel in python and qml updates automatically?

China☆狼群 提交于 2019-12-19 09:59:19
问题 i am trying to insert/edit a python list that is subclassed from QAbstractListModel in pyqt5. this python list is read in the model property of ListView element in qml. i have no issues displaying the data in qml. problem arises when i try to append new data into the python list. the following is what i have done so far: main.py: import sys, model2 from PyQt5.QtCore import QUrl from PyQt5.QtWidgets import QApplication from PyQt5.QtQuick import QQuickView class MainWindow(QQuickView): def _

Remove rows from QAbstractListModel

戏子无情 提交于 2019-12-18 04:55:10
问题 I have a custom model which derives from QAbstractListModel which is exposed to QML. I need to support operations to add new items and remove existing items. While insertion operation works without any problems, removal operation causes the application to crash while calling endRemoveRows() function. void GPageModel::addNewPage() { if(m_pageList.count()<9) { beginInsertRows(QModelIndex(),rowCount(),rowCount()); GPage * page = new GPage(); QQmlEngine::setObjectOwnership(page,QQmlEngine:

Accessing QAbstractListModel item in Qml without using a ListView

我是研究僧i 提交于 2019-12-12 02:26:38
问题 I have subclassed QAbstractListModel in order to have a model on the qml side. I can easily use this model in ListViews and other similar components that deal with models, however, I can't access it directly. This is what I am trying without success: myModel[0].name // TypeError: Cannot read property 'name' of undefined Is this possible? Am I using the wrong syntax? 回答1: (1) You're mixing up roles and properties. You model implements roles which are used to feed a delegate in a view. In your

QQmlListProperty - writable QList violates QML's memory management rules?

拜拜、爱过 提交于 2019-12-11 07:28:22
问题 I've been using QQmlListProperty in a kind of a "master class" that is both in the same time a model and a qml list property, allowing the easy declarative markup of object backbones, which may or may not be modifiable as well as the runtime generation / consolidation of code from dynamic structure. I've shared something approximate in this answer. I have zero idea of the actual implementation details, but what triggers my "spider sense" is the following bits of documentation:

How to customize the display of a QListView

让人想犯罪 __ 提交于 2019-12-11 07:24:51
问题 I have implemented a list of users in my Qt program, using the model/view principle of Qt . My QListView displays a subclass of QAbstractListModel and so far this works just fine. Now I would like to customize the display of my user list (display the name on several line, add IP information, and so on: not really relevant, I just want something really custom). I couldn't find anything in the Qt documentation regarding this: what are my options ? Note: The items in the list do not need to (

How to correctly implement a checkable ListView in QtQuick2?

北慕城南 提交于 2019-12-11 06:54:36
问题 Coming from C++ I dont know how to correctly implement a checkable ListView in QtQuick. For testing purposes I created a small test application. The model: class MyModel : public QAbstractListModel { Q_OBJECT public: MyModel(QObject *parent = Q_NULLPTR) : QAbstractListModel(parent) { for(int i = 0; i < 10; i++) m_items.insert(QString("item%0").arg(i), qrand() % 2 == 0 ? Qt::Checked : Qt::Unchecked); } int rowCount(const QModelIndex& parent) const Q_DECL_OVERRIDE { return m_items.count(); }

Use a QAbstractListModel in another one

巧了我就是萌 提交于 2019-12-10 10:12:33
问题 I have an issue while trying to develop a data model for my application with Qt/QML. I already used a QAbstractListModel to be able to pass customs data model from C++ to QML and it worked like a charm with simple model (such as a model based on strings and bools). But now I need to build a more difficult model and I was wondering if it was possible to use a QAbstractListModel inside another QAbstractListModel . Let me explain myself. I have a data model called model_A build like that : model