PDA

View Full Version : Table Selection



ToddAtWSU
8th March 2007, 18:07
I have a QTable in Qt 3.3 and have it set up so the user selects rows. I have been trying to implement this and have not found a way to do it, but what I want to be able to do is have the user click and drag from say row 3 to row 6 and select all those rows. This I have done but the next step is what I cannot get accomplished. Then the user clicks and drags to select rows 10-15. What I want the final table to look like is Rows 3-6 and rows 10-15 will all be selected. I don't want the table to forget what was previously selected. Is this at all possible? Thanks!

wysota
8th March 2007, 20:34
If the user holds the Control key while dragging, it should work out of the box (provided that the selection mode is set to Multi or MultiRow). If that doesn't satisfy you, then connect to the selectionChanged() signal and store the selection somewhere so that when it changes again (the user drags the other selection) you can add the previous selection to the existing one. I hope I'm clear enough :)

ToddAtWSU
12th March 2007, 16:52
You are very clear. I kind of figured I would have to do it that way but was hoping there would be an easier way. Oh well just another thing to store in memory. Thanks!

wysota
12th March 2007, 17:26
You want to do something that violates some usual behaviour (clearing the selection), so there is no easy way of doing what you want. I believe Qt4 supports the selection behaviour you require (I'm not sure though).

ToddAtWSU
13th March 2007, 21:26
I am overriding the selectionChanged method and having some problems. I first check to see if the row has been hidden since even hidden rows can capture selections and if it has I make sure it is not selected. I have a list of bools whose size is the same number as rows in the table so they have a 1-to-1 correlation as to if they have been previously selected. If they are visible and get selected I turn the variable to true. I then make sure to call selectRow on all the rows whose corresponding boolean is true. I have a flag set up so when I call selectRow it sees I am in the middle of selecting rows and doesn't re-execute my code causing an infinite loop. (selectRow emits a selectionChanged signal causing an infinite loop if not careful). But my problem lies in if the user clicks on the row a 2nd time, I want to deselect this row. How do I capture if the mouse clicked on a row for the 2nd time? Say Row 10 is selected and the user clicks and drags from Row 8 to Row 12, I want 8, 9, 11, 12 to be selected and 10 to be unselected since it was previously selected. I don't see where the selectionChanged signal has a QTableSelection associated with it. Any ideas on how to get around this obstacle would be great. If I am not clear enough please let me know where your confusion lies. Thanks!

ToddAtWSU
15th March 2007, 14:58
Instead of trying to re-write the functionality which is proving to be rather difficult, is it possible to make the QTable believe the Ctrl key is always being pressed down when the user selects objects with the mouse? Since the Ctrl key does give me the functionality I want, this would probably be a very desirable solution. Thanks again for all your help!

ToddAtWSU
26th March 2007, 18:38
I am still having problems with this. I took a break from it but am now back and working at it and was still curious if there is a way to make the table selection think I am always holding the Ctrl button down. Thanks again for all your help!

windflower
26th March 2007, 19:13
Since you already have a list of bools to track the status of the rows, when you have checked that they are visible, then check the selected flag. If the selected flag is already true, then de-select the row and set it to false.