I think he wants to sort the whole tablewidget...in accordance to the column that has been clicked (and sorted)
I think he wants to sort the whole tablewidget...in accordance to the column that has been clicked (and sorted)
Ok, but what is the difference between "whole tablewidget" and the effect he currently experiences?
Well If I were to sort a column, it would sort ONLY that column, not ALL columns, so
If i sort Information1:
Information 1 AND [otherinfo1] [somemoreinfo1] [button1] [othbutton1]
will be in separate rows... So what am I suppose to do?
I'm not sure how I would override the column sorting like that.
Did you guys understand my problem?
In other words, each column item in each row needs to LOCK onto the columns next to it.
Info | Button
1)[info1][button1]
2)[info2][button2]
3)[info3][button3]
Then someone clicks Button header item. Then suddenly, it becomes:
Info | Button
1)[info1][button3]
2)[info2][button2]
3)[info3][button1]
But this will make button3 and info1 next to each other, which is incorrect.
I want it so that when someone clicks "Button" header item.
It sorts like this:
Info | Button
1)[info3][button3]
2)[info2][button2]
3)[info1][button1]
So in other words the numbers need to be locked together. Is this any clearer?
Did you write the sorting code yourself? The table view sorts rows by default, not columns. Maybe the effect is caused by the fact, that you use cell widgets? In that case you'll probably have to move the widgets to appropriate cells yourself.
VireX (6th April 2007)
Yes, I understand your problem :
- You click on a column header to sort data, and you also want the other columns to be adjusted, in order to keep your rows the same !
- If you really want to keep QTableWidget, I think you should :
1) deactivate the default sorting method with setSortingEnabled(false)
2) connect a custom sorting slot to the header signal sectionClicked()
3) implement your custom sorting function to sort just like you want
VireX (6th April 2007)
Thanks for the help guys. However, I tried a small test with random text in the cells, and it turns out wysota is right, it is automatically locked... I am so shocked, I tested it before and I coulda sworn it wasn't like that! I cannot believe it... But I definitely belong to this forum for another month now.
So I am trying to use a loop, I am adding some information onto the QTableWidget.Qt Code:
for(int i = 1; i < 53; i++){ TableW->setItem(i-1, 0, t_Items[i-1]); TableW->setItem(i-1, 1, p_Items[i-1]); TableW->setItem(i-1, 3, s_Items[i-1]); TableW->setItem(i-1, 4, i_Items[i-1]); }To copy to clipboard, switch view to plain text mode
There are already 55 rows available, and I'm adding them onto the table, but for some reason, the program usually crashes.
all the t_Items and other Items are QList<QTableWidgetItem *>
You should post a larger sample of code, a compilable one would be the best.
Also, post the debug backtrace of your crash !
I cannot debug. When I debug, there is no problem except that
setItem for column 2-4-5 don't work except for the VERY LAST row (52)
My logs say, that it stops recording in the game loop (counts to 52 and program crashes) when NOT DEBUGGING;;;; when debugging... absolutely no problems.
You know what nvm, you guys don't see anything wrong with it.
Also, the fact that me commenting out CreateList(), still causes a crash (but this time moves to end of the program), but when theres CreateList() (with almost no code except a log function, which proves its something related to my program and not Qt Table).
Ok one last question
Let's say I have 2 pushbuttons:
label: Add
Labal: Del
If I were to setCellWidget the pushbutton to one column, but if I were to click the header "to sort", would it sort all the Add buttons at top and Del buttons at bottom (or vice-versa)? or would it not know how to sort PushButtons?
Is there any sample sorting code, to sort some widgets or something?
Last edited by VireX; 6th April 2007 at 19:20.
Bookmarks