PDA

View Full Version : QTable Selection Issue



ToddAtWSU
31st January 2007, 15:01
I have a QTable (Qt 3.3.7) in which the user can click checkboxes to hide and show different rows in the table. The user can also select multiple rows inside the table and do things with those rows by clicking different buttons. The problem I am having is occuring with the selecting of these rows. Here is an example of what is happening:

The user has 30 rows showing and clicks a checkbox that hides all the odd-numbered rows. So the user now has 15 rows showing and selects all of these by clicking and dragging from the first one down to the last one. The first problem is this also selects all the hidden rows between rows 2-30 where I just want the visible rows to be selected. I connected the selectionChanged( ) SIGNAL to a SLOT I created called changeSelection that went through and said if the row was selected and the row was not visible, then remove the selection for that row. This works fine until I click the checkbox to show all the odd-numbered rows. Upon doing this, the rows I now tell to show also appear as selected. I want these rows to stay un-selected whenever I tell them to re-appear.

What do I need to do to ensure these rows stay un-selected upon making them re-appear? :confused: Thanks for all your help!!

wysota
6th February 2007, 13:51
What selection mode do you use? You should use QTable::MultiRow selection and don't use "shift" for row selection as this selects ranges.

An alternative is to manually unselect all rows that are hidden after a successfull selection - just connect to the selectionChanged() signal and iterate over items.

ToddAtWSU
6th February 2007, 14:31
I do use QTable::MultiRow for the selection and I need to be able to allow the user to click-and-drag a selection by clicking on one row, and dragging say 5 rows down so all the rows from the click and release are selected. As you can see from my post above, I do connect to the selectionChanged( ) signal and tell it to unselect the row. But when I choose to re-show those rows they now come up selected and I want them to stay unselected. Is there any way I can I tell it to stay un-selected? So I am doing all the things you suggest. Do you have any other ideas? Thanks!

wysota
6th February 2007, 14:37
What if you store the current selection on selectionChanged() somewhere and when you show the rows which were hidden, compare them with the stored selection and make sure only those items are selected which have been previously stored?

1. store a list of visible selected items
2. when you show items:
a) deselect all rows (watch out not to fall into an infinite loop as selectionChanged() will be emitted)
b) select only those rows which were stored in (1)