PDA

View Full Version : QTreeWidget (Row Check, Custom Sort)



AaronMK
31st December 2007, 23:00
Hello,

I am trying to do the following three things with an application much like the one attached:

1) Attach the check box to the full table row, as opposed to just an item in the table - Right now, it moves with the column if the user changes the column order. Is it possible for the check to always be left-most widget?

2) Custom sort the IP address field - Can i make a custom sort routine for a single column of the table, or use one of the other item roles so I can have it sort directly on QHostAddress data, instead of the string data? (as in "192.168.0.1, 192.168.0.2, 192.168.0.101, 192.168.0.201" instead of "192.168.0.1, 192.168.0.101, 192.168.0.2, 192.168.0.201")

3) Is there a way to quickly automate the hiding and showing of individual columns, the the common context menu on most file explorers' detail view?

Thank you for your assistance.

jacek
1st January 2008, 01:24
You can control the sort order by reimplementing QTreeWidgetItem::operator<() (http://doc.trolltech.com/4.3/qtreewidgetitem.html#operator-lt).

marcel
1st January 2008, 01:37
You can control the sort order by reimplementing QTreeWidgetItem::operator<() (http://doc.trolltech.com/4.3/qtreewidgetitem.html#operator-lt).
Just keep in mind that a alphanumeric sort will be performed. To achieve what you want you will have to sort on each IP byte. So if you have the IP: 194.102.98.10 then you'll have to split it in 4 bytes: 194, 102, 98 and 10. You must do this for all IP's; the 4th byte will have the highest priority, while the 1st byte the lowest.



Attach the check box to the full table row, as opposed to just an item in the table - Right now, it moves with the column if the user changes the column order. Is it possible for the check to always be left-most widget?

Create another column(first column) which will contain only the check box.



Is there a way to quickly automate the hiding and showing of individual columns, the the common context menu on most file explorers' detail view?

After briefly looking at your code, it seems to me that it is not easy to extended it in the direction you want.
You must always recreate the items after hiding the columns.

Bottom line is that in a long run you'd be better if you use a QTreeView + some model.
For hding/showing columns you can easily use QHeaderView::hideSection() and QHeaderView::showSection().

AaronMK
8th January 2008, 16:55
Thank you again for your assistance.


To achieve what you want you will have to sort on each IP byte.

The QHostAddress::toIPv4Address () method worked well for this.


After briefly looking at your code, it seems to me that it is not easy to extended it in the direction you want.
...
Bottom line is that in a long run you'd be better if you use a QTreeView + some model.

Our model in the actual application is pretty deeply entrenched with a shipping date for the next release very near. However, this suggestion pops up so often with QTreeWidget related questions. Moving to Qt's official data model will be a serious consideration for the next release.

Code with a couple of suggestions implemented attached for reference.