PDA

View Full Version : QTableWidget Sorting Widgets!



VireX
9th April 2007, 00:42
IS there any way for me to sort buttons?
Say I have a button called EditBox, DeleteBox, I want to put all rows with EditBox cellWidgets on the top, and all DeleteBox should be below, and it also should sort by number as well.

so an example would be:
45 Edit
46 Edit
47 Edit
48 Edit
1 Delete
2 Delete
3 Delete
4 Delete
5 Delete

How would I code a sorting scheme for that? I believe I would connect headerView() to sectionClicked, and maybe write a function for it, but I have no idea how I would write the function.

jpn
12th April 2007, 14:55
Reimplement QTableWidgetItem::operator<() (http://doc.trolltech.com/4.2/qtablewidgetitem.html#operator-lt) and make sure sorting is enabled (http://doc.trolltech.com/4.2/qtableview.html#sortingEnabled-prop).

VireX
13th April 2007, 00:22
That's not going to help because a cell Widget is not a TableWidgetItem... so reimplementing that won't help.

I believe I do have to edit the headerView.

jpn
13th April 2007, 07:54
That's not going to help because a cell Widget is not a TableWidgetItem... so reimplementing that won't help.
Create items underneath cell widgets. You can even get away with plain QTableWidgetItem if the content is plain textual or numerical data and set on both, on the button and on the item. In case you need smarter sorting, you need to reimplement the aforementioned operator.

VireX
14th April 2007, 01:08
Wow, thank you, I didn't know you can setItem ANNNNDD setCellWidget too.