QTreeView internal move: not all columns shown
-
Simple scenario:
QStandardItemModel
,QTreeView
and aQSortFilterProxyModel
.So far, everything is working as expected. Now I'm working on a feature allowing the user to create a new group (item in the tree view) and then adding existing items into that group (re-parenting via
QAbstractItemView::InternalMove
).While the row is being moved as expected, not all columns show up anymore.
Here are two screenshots: Before the move and after the move.Before move:
After moving the row with ID
5
to the groupTest Group 1
:
My expectation would have been that after the move (re-parenting), the row would still show all columns (
ID
,Name
andDescription
). But instead, only theDescription
column is shown.Why is this happening and how can I achieve the expected behavior in that each row still populates/shows all the columns accordingly but is just nested in zero or more parent groups?
-
Hi,
Did you check that it is the correct index that is moved ? I.e that it's the first column index that you move ?
Do you have the same issue without the proxy ?
-
Hi,
Did you check that it is the correct index that is moved ? I.e that it's the first column index that you move ?
Do you have the same issue without the proxy ?
@SGaist said in QTreeView internal move: not all columns shown:
I.e that it's the first column index that you move ?
Sorry for the late reply. Your question kind of threw me off. I didn't understand why you'd ask this. As per my understanding this shouldn't matter as I want to remove an entire row. However, knowing you (minus the outstanding beer) I was fairly sure that you wouldn't ask this unless it would be important. Hence I needed some time to think about it :D
So what basically happened is that I only set the
Qt::ItemIsDragEnabled
flag on ONE item of the row (eg. cell). Hence the other items were not moved (although the row still disappeared in the view). Once I added theQt::ItemIsDragEnabled
flag to all items of the row things started looking more the way I expected.As mentioned this is my first time using
QStandardItemModel
. I haven't really faced this issue previously as I'd simply subclassQAbstractItemModel
and implementingitemFlags()
accordingly.
I feel like I am using theQStandardItemModel
incorrectly. To achieve the visual appearance showed in my initial screenshot I am creating threeQStandardItem
s for each row and adding them usinginvisibleRootItem()->appendRow()
:void model::add(const process& p) { const Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; // ID auto item_id = new QStandardItem(); item_id->setText(QString::number(p.id)); item_id->setFlags(flags); // Name auto item_name = new QStandardItem(); item_name->setText(p.name); item_name->setFlags(flags); // Description auto item_description = new QStandardItem(); item_description->setText(p.description); item_description->setFlags(flags); invisibleRootItem()->appendRow({ item_id, item_name, item_description }); }
Is this the way to go? It just doesn't feel right.
-
I don't see anything wrong. The invisible root item is the initial item that allows to keep together all the others. Whether you have a tree like model or table like does not matter.
-
Alright, after getting this to work I decided to not use
QStandardItemModel
anymore but instead directly deriving fromQAbstractItemModel
as I've usually done. It was a fun little adventure tho.Thank you for your help!