Results 1 to 7 of 7

Thread: QTreeView: selection behavior upon selected item removal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: QTreeView: selection behavior upon selected item removal

    I have solved it this way in my QTreeView subclass, but there must/ought to be a way for doing this by configuring Qt objects.

    Qt Code:
    1. void TreeView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end )
    2. {
    3. if (selectionMode() == QAbstractItemView::SingleSelection)
    4. {
    5. QModelIndexList selectedRows = selectionModel()->selectedRows();
    6. if (selectedRows.size() == 1 && selectedRows[0].parent() == parent && selectedRows[0].row() >= start && selectedRows[0].row() <= end)
    7. {
    8. // the rows about to be removed contain the single selected item
    9. selectionModel()->clear();
    10. }
    11. }
    12. QTreeView::rowsAboutToBeRemoved (parent, start, end);
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView: selection behavior upon selected item removal

    The QAbstractItemModel::rowsAboutToBeRemoved() signal gives you in parameter the parent index and the row of removed object.
    So you can connect that to your proper slot outside the treeview and decide to call clearSelection() (it is a public slot) or not following tests on removed rows.

    No ?

    But I'm not afraid about subclassing QTreeView, anyway...
    Last edited by roro; 11th July 2007 at 16:05.

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.