PDA

View Full Version : Sorting disabled?



unsortedTable
5th December 2018, 14:10
Hi,
im relatively new to QT and am clueless right now.
I have a QTablewidget, that i populate with "table->setCellWidget(row, column, new QLabel(somestuff))" while populating setSortingEnabled is disabled and after the populating is finished re enabled.
The sortIndicator seems to work somehow. By clicking the Columns the indicator changes, but nothing else. The order of the table stays the way it was before. Nothing changes at all in the table.
What could i have done to disable sorting all together, or are additional steps needed for the sorting to work at all?

Edit: sortByColumn and sortItems also have no effect on the Table.

I'd love to hear some answers. And have a great day.
Random Guy

tuli
5th December 2018, 14:25
You should use a model instead of setting widgets directly.

https://doc.qt.io/qt-5/model-view-programming.html#model-subclassing-reference


Also why are you using a QLabel? If you just want to show a string, that's total overkill.

Sorting doesnt work because Qt wont look into the label to find your string and sort by that. It cant sort widgets.

unsortedTable
5th December 2018, 15:39
Thanks.
Tried with all kinds of other Types for Strings and numbers. The only one that worked at that time were Labels then i just kept them.
Edit: Topic can be closed.
TL;DR: CellWidgets will not be sorted.