Results 1 to 3 of 3

Thread: Custom selection actions in QTreeView

  1. #1
    Join Date
    Oct 2009
    Location
    Maryland
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Custom selection actions in QTreeView

    I have a QTreeView. I'd like to alter the way selection works. When a user selects an intermediate node, I need to select all subordinate nodes as well, and possibly change selection status of superior nodes in the tree (data or selection status).

    I've tried working with the selectionChanged signal, but that induces some undesirable feedback (selection changes at this stage cause another iteration of event loop processing, and it can be difficult to differentiate user vs. programmatic changes in subsequent invocation of the selectionChanged signal). I'd like to have a method that gets called *before* anything is selected, so that I can decide what (if anything) gets selected/deselected. Is this possible?

    Should I subclass QTreeView and write my own selectionCommand() method? The (minimal) documentation for this hints at doing this to "define your own selection behavior" but I'm not sure if that really means "define your own QAbstractItemView::SelectionBehavior" which isn't what I really want.

    What's the right way to do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Custom selection actions in QTreeView

    If you are in you slot, called by the selectionChanged singnal, you could useQObject::disconnect() or QObject::blockSignals(). After alter your selection unblock or reconnect the signal.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom selection actions in QTreeView

    How about subclassing QItemSelectionModel and then using QTreeView->setSelectionModel(&myselectionmodel) ? As far as I'm aware, thats responsible for all selection actions - its what keeps the selection status of all the items. The 'select' call will be called to actually do the select, so you can decide whether or not you want the item selected, and whether or not to select or items as a result.

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 08:52
  2. Custom context menu in QTreeView
    By ttvo in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2009, 23:29
  3. Selection row in QtreeView
    By visor_ua in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2008, 23:31
  4. Qtreeview selection highlighted problem?
    By thefisher in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2006, 10:50
  5. Add custom QTreeView in VS .NET
    By wind in forum Newbie
    Replies: 4
    Last Post: 5th October 2006, 18:04

Tags for this Thread

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.