Results 1 to 4 of 4

Thread: QTable Selection Issue

Hybrid View

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

    Red face QTable Selection Issue

    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? Thanks for all your help!!

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

    Default Re: QTable Selection Issue

    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.

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

    Default Re: QTable Selection Issue

    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!

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

    Default Re: QTable Selection Issue

    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)

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. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 20:31
  3. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50
  4. QListWidget selection behavior
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2006, 14:10
  5. QTable..Vs.. QListView
    By :db:sStrong in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 21:03

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
  •  
Qt is a trademark of The Qt Company.