Results 1 to 8 of 8

Thread: Table Selection

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Table Selection

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Table Selection

    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

  3. The following user says thank you to wysota for this useful post:

    ToddAtWSU (12th March 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Table Selection

    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!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Table Selection

    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).

  6. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Re: Table Selection

    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!

  7. #6
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Table Selection

    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!

  8. #7
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Table Selection

    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!

  9. #8
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Table Selection

    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.

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. Model sorting vs. selection
    By VlJE in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 16:46
  3. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  4. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50
  5. Adding row in a Table after selected row
    By ankurjain in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2006, 18:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.