qtreeview

Understanding Qt view-model architecture: when to create and how to cleanup indexes in QAbstractItemModel implementation?

喜夏-厌秋 提交于 2019-12-01 09:27:23
I'm currently migrating my project from QTreeWidget to QtreeView , and have a lot of problems caused by poor understanding of the Qt model-view design. So far I couldn't find answers even in Qt examples. I've implemented my QAbstractItemModel . I'm returning strings to be viewed in the QTreeView through data method. Now, the underlying data will change in runtime. To handle this my model is subscribed to a notification that does emit dataChanged(index(0,0), index(rowCount() - 1, LastColumn)); . The question is: how to create and cleanup QModelIndex objects? One of the Qt examples reimplements

When to emit dataChanged from a QAbstractItemModel

女生的网名这么多〃 提交于 2019-12-01 06:46:03
In Qt, I have a model subclassing QAbstractItemModel - it's a tree displayed in a QTreeView. The model supports various forms of change which all work OK. The two of relevance are: 1) Some data in a small number of related rows changes 2) A visualisation change means that the majority of rows should change their formatting - in particular they have a change of background highlighting. Their DisplayRole data does not change. The current design deals with both of these in the same way: for every row that has any change the model emits dataChanged(start_of_row_index,end_of_row_index) . I emit the

Understanding Qt view-model architecture: when to create and how to cleanup indexes in QAbstractItemModel implementation?

做~自己de王妃 提交于 2019-12-01 06:41:53
问题 I'm currently migrating my project from QTreeWidget to QtreeView , and have a lot of problems caused by poor understanding of the Qt model-view design. So far I couldn't find answers even in Qt examples. I've implemented my QAbstractItemModel . I'm returning strings to be viewed in the QTreeView through data method. Now, the underlying data will change in runtime. To handle this my model is subscribed to a notification that does emit dataChanged(index(0,0), index(rowCount() - 1, LastColumn));

When to emit dataChanged from a QAbstractItemModel

狂风中的少年 提交于 2019-12-01 05:01:43
问题 In Qt, I have a model subclassing QAbstractItemModel - it's a tree displayed in a QTreeView. The model supports various forms of change which all work OK. The two of relevance are: 1) Some data in a small number of related rows changes 2) A visualisation change means that the majority of rows should change their formatting - in particular they have a change of background highlighting. Their DisplayRole data does not change. The current design deals with both of these in the same way: for

qt: pyqt: QTreeView internal drag and drop almost working… dragged item disappears

空扰寡人 提交于 2019-11-30 23:47:36
I almost have a completely working drag and drop re-order within a QTreeView. Everything seems to be ok except the dropped object never appears (though I can reference it numerous different ways that proves to me that it actually exists where it should be). If anyone has a moment and could run the following code and let me know what I am doing wrong I would really appreciate it. I have been banging my head against this process for over a week now: You should be able to just copy and run the following code (I have a bunch of print statements in it that seem to indicate that everything is

Changing the row background color of a QTreeView does not work

岁酱吖の 提交于 2019-11-30 19:42:53
I have a QTreeView and want different background colors for rows, depending on their content. To achieve this, I derived a class MyTreeView from QTreeView and implemented the paint method as follows: void MyTreeView::drawRow (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionViewItem newOption(option); if (someCondition) { newOption.palette.setColor( QPalette::Base, QColor(255, 0, 0) ); newOption.palette.setColor( QPalette::AlternateBase, QColor(200, 0, 0) ); } else { newOption.palette.setColor( QPalette::Base, QColor(0, 0, 255) ); newOption

qt: pyqt: QTreeView internal drag and drop almost working… dragged item disappears

旧时模样 提交于 2019-11-30 17:23:17
问题 I almost have a completely working drag and drop re-order within a QTreeView. Everything seems to be ok except the dropped object never appears (though I can reference it numerous different ways that proves to me that it actually exists where it should be). If anyone has a moment and could run the following code and let me know what I am doing wrong I would really appreciate it. I have been banging my head against this process for over a week now: You should be able to just copy and run the

To set widgets on children items on QTreeView

眉间皱痕 提交于 2019-11-30 15:41:36
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(QTreeView): def __init__(self): super(PrvTreeviewNest, self).__init__() loadUi('/home/user

Changing the row background color of a QTreeView does not work

喜夏-厌秋 提交于 2019-11-30 03:13:49
问题 I have a QTreeView and want different background colors for rows, depending on their content. To achieve this, I derived a class MyTreeView from QTreeView and implemented the paint method as follows: void MyTreeView::drawRow (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionViewItem newOption(option); if (someCondition) { newOption.palette.setColor( QPalette::Base, QColor(255, 0, 0) ); newOption.palette.setColor( QPalette::AlternateBase,

PyQt Tree Widget, adding check boxes for dynamic removal

北城以北 提交于 2019-11-30 03:01:23
I am attempting to create a tree widget that will essentially allow the user to view various breakdowns of data and have the option to delete certain items. In order to do this I want to have check boxes associated with each top level item and each child so the user can select which top level items (and thus all the children of that top level item) to delete. Or which specific children to delete. To give you a better idea I've created an example where [x] represents a checked check box and [ ] represents an empty checkbox: >Beverages Allowed in Stadium [ ] Soda [ ] Water [ ] Tea [ ] Spirits [X