I just found this
<http://stackoverflow.com/questions/21564976/how-to-create-a-proxy-model-that-would-flatten-nodes-of-a-qabstractitemmodel-int>SO
thread
<http://stackoverflow.com/questions/21564976/how-to-create-a-proxy-model-that-would-flatten-nodes-of-a-qabstractitemmodel-int>:
|view
=QtGui.QTreeView()view.setModel(model)view.expandAll()view.setIndentation(0)view.header().hide()|
I haven't tries it yet but it looks like it's perfect for my need.
Just wanted to post it here for posterity.
Cheers,
frank
On 27/04/17 1:29 PM, Frank Rueter | OHUfx wrote:
So I read the SO post but feel that my task is way simpler than the
one stated in that post.
As mentioned before, all I am trying to achieve is a flattened list
view and a tree view feeding off the same data, e.g.:
QListView should ignoring existing parenting and show:
* itemA
* itemB
* itemC
QTreeView of the same model would show (based on previous parenting):
itemA
|___itemB
|____itemC
Ideally I'd use a proxy model to "un-parent" all items to feed the
list view, while the original model retains it's hierarchy and thus
yields the expected tree view.
Is this possible to do through a proxy model? I have only ever used a
QSortFilterProxy so far.
Thanks,
frank
On 27/04/17 3:47 AM, Kevin Funk wrote:
On Wednesday, 26 April 2017 21:32:13 CEST Frank Rueter | OHUfx wrote:
You are dead right as my follow up email confirms.
Now the question is how to use the same (parented) item in a tree view
and a list view.
That's discussed over here:
http://stackoverflow.com/questions/19498753/append-qstandarditem-in-two-qstandarditemmodel-at-the-same-time
You might want to start writing a proper model (QAbstractItemModel based)
instead. Or you'll need to create copies of the QStandardItems (which is
probably undesired as you manually need to keep them in sync if needed).
Hope that helps,
Kevin
I guess I will be RTFM-ing a bit.
Cheers,
frank
On 26/04/17 9:24 PM, Kevin Funk wrote:
On Wednesday, 26 April 2017 19:50:54 CEST Frank Rueter | OHUfx wrote:
Hi,
I seem to run into this issue a lot and I don't get why:
I have a list of sub-classed QStandardItems that another processor
generated, and I want to add them to a QStandardItemModel like this:
for item in myItemList:
self.model.appendRow(item)
The model is empty and hasn't been used at this point. Yet I get none of
my items but one of those errors for each item:
QStandardItem::insertRows: Ignoring duplicate insertion of item
Use the source, Luke :)
QStandardItemModel::appendRow calls
- QStandardItem::appendRow which calls
- QStandardItem::insertRow which calls
- QStandardItemPrivate::insertRows [1]
Excerpt from QStandardItemPrivate::insertRows:
```
//...
if (item->d_func()->parent == 0) {
item->d_func()->setParentAndModel(q, model);
} else {
qWarning("QStandardItem::insertRows: Ignoring duplicate insertion of
item
%p",
item);
item = 0;
}
//...
```
=> The warning is thrown when your items already have a parent set
Is that the case for you?
Hope that helps,
Kevin
PS: The Woboq code browser is an awesome tool to follow call chains (or
any
decent IDE will do, if you have the Qt sources)
[1]https://code.woboq.org/qt5/qtbase/src/gui/itemmodels/
qstandarditemmodel.cpp.html#_ZN20QStandardItemPrivate10insertRowsEiiRK5QLi
stIP13QStandardItemE>
I know I should know this but I can't figure out why this is happening.
Is there something special I need to do when subclassing QStandardItem?
Cheers,
frank
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest