Results 1 to 1 of 1

Thread: qtableview extended selection mode problem

  1. #1
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qtableview extended selection mode problem

    I have a QTableView with

    setSelectionBehavior(QAbstractItemView::SelectItem s);
    setSelectionMode(QAbstractItemView::ExtendedSelect ion);

    When I select individual items or I use the control key modifier I get exactly the results I expect when I call

    QItemSelection selRow(model()->index(row, 0), model()->index(row, 0));
    selectionModel()->select(selRow, QItemSelectionModel::Select | QItemSelectionModel::Rows);

    But when I make my selection using the shift modifier I see some apparently incorrect sets of behavior.

    1. The first row selected before using the shift modifier to select the whole set of rows will be deselected. This only happen when the focus was not on the tableview when the first row was selected and there were no current selections or when the row before the shift select was selected using the control key. When I watch what is happening in the debugger in selectionChanged() I see that the selected rows after the shift select include all row numbers except the initial selected row. This is what I would expect since I would expect the code snip-it above to add those rows to the existing list of selected rows just like it adds new selected rows when the control key modifier is used.

    Has anyone seen this before? Any ideas about why this is happening?

    This is with Qt 4.7 on a Windows 7 box.


    Added after 4 minutes:


    Just in case here is a more complete code snip-it.

    Qt Code:
    1. void SelectedManagersTableWidget::selectionChanged(QItemSelection const& selected, QItemSelection const& deselected)
    2. {
    3. if (selected.indexes().size()>0)
    4. {
    5. std::set<int> selRows = getSelectedRowsFast(selected);
    6. BOOST_FOREACH(int row, selRows)
    7. {
    8. QItemSelection selRow(model()->index(row, 0), model()->index(row, 0));
    9. selectionModel()->select(selRow, QItemSelectionModel::Select | QItemSelectionModel::Rows);
    10. }
    11. }
    12.  
    13. if (deselected.indexes().size()>0)
    14. {
    15. std::set<int> unselRows = getSelectedRowsFast(deselected);
    16. BOOST_FOREACH(int row, unselRows)
    17. {
    18. QItemSelection unselRow(model()->index(row, 0), model()->index(row, 0));
    19. selectionModel()->select(unselRow, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
    20. }
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 


    Added after 13 minutes:


    OK I found it. I was doing something dumb. So never mind.
    Last edited by hvengel; 1st November 2011 at 21:28.

Similar Threads

  1. QGraphicsScene and Extended Selection of items
    By totem in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 08:37
  2. Replies: 0
    Last Post: 20th December 2009, 20:54
  3. QTableView - alignment/selection problem
    By Nesbitt in forum Qt Programming
    Replies: 7
    Last Post: 30th November 2009, 02:37
  4. QTableView selection problem
    By aiprober in forum Qt Programming
    Replies: 12
    Last Post: 9th June 2008, 11:55
  5. extended selection in q3listview
    By sreedhar in forum Qt Programming
    Replies: 7
    Last Post: 13th November 2006, 09: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.