Results 1 to 2 of 2

Thread: QItemSelectionModel::selectedColumns returns empty list

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question QItemSelectionModel::selectedColumns returns empty list

    I have subclassed QTableView and inside of it there are 8x8 (64) cells. Now, I am trying to reimplement selectionChanged() slot. Here is declaration:
    Qt Code:
    1. protected slots:
    2. void selectionChanged(const QItemSelection& selected,
    3. const QItemSelection& deselected);
    To copy to clipboard, switch view to plain text mode 
    and here is implementation:
    Qt Code:
    1. void CTableView::selectionChanged(const QItemSelection& selected,
    2. const QItemSelection& deselected)
    3. {
    4. // qDebug() << "\nBEGIN\nSelected cell:" << selected.indexes() <<
    5. // "\nDeselected cell:" << deselected.indexes() <<
    6. // "\nCurrently selected cells (history):" << this->selectionModel()->selectedIndexes() <<
    7. // "\nEND\n";
    8.  
    9. foreach(QModelIndex modelIndex,
    10. selected.indexes())
    11. {
    12. // qDebug() << "\nmodelIndex.row():" <<
    13. // modelIndex.row() <<
    14. // "\n";
    15. qDebug() << "\nthis->selectionModel()->selectedColumns(modelIndex.row()):" <<
    16. this->selectionModel()->selectedColumns(modelIndex.row()) <<
    17. "\n";
    18. // if(this->selectionModel()->selectedColumns(modelIndex.row()).size()<=0)
    19. // {
    20. // qDebug() << "\nOnly one cell selected:\n" <<
    21. // this->selectionModel()->selectedColumns(modelIndex.row()).size() <<
    22. // "\n";
    23. // }
    24. // else
    25. // {
    26. // qDebug() << "\nMore than one cell selected\n";
    27. // }
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 
    When I click on some cell, the slot is launched, but
    Qt Code:
    1. this->selectionModel()->selectedColumns(modelIndex.row())
    To copy to clipboard, switch view to plain text mode 
    returns empty list:
    this->selectionModel()->selectedColumns(modelIndex.row()): ()
    Why??selectedColumnsEmpty.jpgAs you can see from screenshot, I've selected a cell, but selectedColumns() list is empty.
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QItemSelectionModel::selectedColumns returns empty list

    Nice job with the Magic Marker on the screenshot. Hope you were able to clean it off your monitor

    Doe the modelIndex row and column match what you think you have selected? The QItemSelectionModel::selectionChanged() signal represents a delta - if you have single cell selection enabled, the selected argument contains the new selection, the deselected argument contains the previous selection. If you have multiple selection enabled, then the selected argument contains only the new items added to the previous selection, not the entire set of selected items. Likewise, the deselected argument will contain only the items that have been reomved from the selection since the previous change.

    I find it more reliable to ignore these arguments. I retrieve the QItemSelectionModel pointer from the view and simply call QItemSelectionModel::selection() or QItemSelectionModel::selectedIndexes(). Either of these calls will return you the complete set of the currently-selected indexes.

Similar Threads

  1. QGrapchisSvgItem childItems list empty
    By Hogwarts in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2011, 12:18
  2. Replies: 1
    Last Post: 31st July 2009, 20:03
  3. QSplitter::saveState returns empty string
    By miraks in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2008, 21:30
  4. Replies: 2
    Last Post: 19th September 2008, 05:21
  5. QDataStream, QTreeWidgetItem, empty list
    By baca in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2007, 14:43

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.