qabstractitemmodel

QTableView with QStandardItemModel: How to perform live updates during editing a cell?

假如想象 提交于 2019-12-25 17:10:13
问题 Recently, I made the switch to QT. It has taken some time, but I am starting to find my way around. However, one issue remains: I want to port a program, that responds to every key press while editing a cell in a table view (QTableView with QStandardItemModel). The idea is to show and update a list of possibilities on a separate form while the user is entering a text in a table view's cell. After every key stroke, the list needs to be updated according to the current text in the edit field of

QTreeView always displaying the same data

送分小仙女□ 提交于 2019-12-24 07:38:30
问题 I have a tree of items. It is like this: Categorias (root) - General --- Computadoras --- Tablets - Insumos --- Cartuchos The problem is that the QTreeView is being completed always with the same information. I get a tree view looking like this: Categorias (root) - General --- General --- Insumos - Insumos --- General I have put a "print" in the index() method in order to see if the index was being created, and then, when I enter, for example, the "General" category for the first time,

How can I get the background color returned by model take precedence over the style

守給你的承諾、 提交于 2019-12-23 05:41:18
问题 I have a QTreeView rendering QAbstractItemModel , where I would like to set the background of certain cells based on the data in the model. I return QBrush from model::data(Qt::BackgroundColorRole) and it works until I apply a style to an item. Setting any style to the item (even something that has nothing to do with background color, e.g. styling the border) overrides the color I return from the model (the calls to the model querying the background color are made). I.e. the view behaves as

QML view wont update when adding a new item to a QAbstractListModel based model

自闭症网瘾萝莉.ら 提交于 2019-12-19 08:02:14
问题 I've figured out how to bind a model derived from QAbstractListModel to a QML view. But the next thing I tired does not work. If a new Item is added to the model the QML view will not update. Why is that? DataObject.h class DataObject { public: DataObject(const QString &firstName, const QString &lastName): first(firstName), last(lastName) {} QString first; QString last; }; SimpleListModel.h class SimpleListModel : public QAbstractListModel { Q_OBJECT enum /*class*/ Roles { FIRST_NAME = Qt:

QTreeView & QAbstractItemModel & insertRow

十年热恋 提交于 2019-12-19 07:51:27
问题 I'm trying to implement QAbstractItemModel for QTreeView. I have problem with inserting rows. I noticed that if I insert at the beginning of my application all works fine. But If I insert rows later - after some other operations (like selections etc.) new items stay invisible. Moreover QTreeView seems to doesn't work at all! Do I have to emit some signals to notify QTreeView about rows insertion? This is my insertion method: bool LayersModel::insertRows(int position, int count, const

QTreeView with custom items

喜夏-厌秋 提交于 2019-12-19 04:05:58
问题 I'm writing my first Qt application with PySide and am having some trouble creating a custom tree view. I'd like to list my own data in one column. Each item must have text with tooltip, different text color, different background color, icons with actions and tooltip. The default tree works. I have view: class TreeView(PySide.QtGui.QTreeView): and model: class TreeModel(PySide.QtCore.QAbstractItemModel): How can I add different icons to my items? Here is my example: import sys from PySide

To set widgets on children items on QTreeView

喜欢而已 提交于 2019-12-18 17:28:19
问题 Thanks to this thread, I'm able to add widgets to 2nd or later column of QAbstractItemView (in my example QTreeView) of top level items of a view . But is it possible to add widgets to the children items? Here's what I've tried which partly went well: #!/usr/bin/env python import os from PyQt4.QtCore import QModelIndex, Qt from PyQt4.QtGui import QApplication, QItemSelectionModel, \ QPushButton, QStandardItem, \ QStandardItemModel, QTreeView from PyQt4.uic import loadUi class PrvTreeviewNest

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:

Editable reorderable (by drag and drop) Qt5 QTreeView example

主宰稳场 提交于 2019-12-13 05:43:21
问题 after being unable to find a decent generic hierarchical reorderable drag and drop example for Qt5's QTreeView, I tried to transform the Editable Tree Model example code accordingly. There's an related question recorded at: QTreeView with drag and drop support in PyQt, but while it's PyQt4, which isn't a problem in itself (I'm going to convert this to PyQt anyway ;)), the treeview + abstract model doesn't work properly. At least, it doesn't reorder any items here. This example code doesn't

QTableView QStandardItemModel revert or undo user entry

不问归期 提交于 2019-12-13 04:19:48
问题 How can I undo or revert an user entry on a QTableView popuplated by QStandarItemModel? I have connected dataChanged signal with a handler where I validate the data... connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(validateData(QModelIndex,QModelIndex))); ...but in case user entry is wrong I want to revert or undo the user entry to the previous value of the item. I have read about revert() member inherited from QAbstractItemModel but I can't understand how it works