Results 1 to 4 of 4

Thread: QTreeWidget selection

  1. #1
    Join Date
    Apr 2007
    Location
    Moscow, Russia
    Posts
    20
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidget selection

    Hello!

    I have a problem. My program's functionality depends on type of current item in QTreeWidget and of the count of selected items:

    Qt Code:
    1. // Signal currentItemChanged(...) handler
    2. void Class1::Handler(QTreeWidgetItem* pCurItem, QTreeWidgetItem * pPrevItem)
    3. {
    4. ..
    5. if (tree->selectedItems().count() > 1)
    6. {
    7. ...
    8. }
    9. else
    10. {
    11. if (pCurItem->data(0, Qt::UserRole).toString() == "example1")
    12. {
    13. ...
    14. }
    15. else
    16. {
    17. ...
    18. }
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    QTreeWidget selection mode is ExtendedSelection.
    For example, i select in tree 5 items (by mouse). It works correct.
    > Item1
    > Item2
    > Item3
    > Item4
    > Item5

    Then, i click to one item of that 5.
    Item1
    Item2
    > Item3
    Item4
    Item5

    And here is the problem. My handler works as if it was selected 5 items...Maybe QTreeWidget class has some function, that force tree to refresh selected list?

    Thank you!
    Denis Davidov

  2. #2
    Join Date
    Sep 2006
    Posts
    46
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget selection

    Since Item3 is one of the items already selected along with item1-item5 it will not trigger currentItemChanged() when you click on it.

    You would also need to connect itemClicked() in combination with your current setup for the result you desire. This will also have the side effect of both calls being triggered if the item was not previously selected.

  3. #3
    Join Date
    Apr 2007
    Location
    Moscow, Russia
    Posts
    20
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget selection

    Thank you! Now it works. I handled currentItemChanged() and itemSelectionChanged() and it works by mouse selection and keyboard too.
    Denis Davidov

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget selection

    Keep in mind that "current item" and "selected items" are related but still different concepts. Current item is the one which has keyboard focus. There can never be more than one current item. However, depending on the selection mode, there can be one or multiple selected items. It's also possible that none of selected items is current item (keyboard navigation).
    J-P Nurmi

Similar Threads

  1. QTreeWidget and keep "focus drawing" every time
    By Lykurg in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2008, 18:04
  2. QTreeWidget select item
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2007, 15:26
  3. Replies: 1
    Last Post: 8th March 2007, 11:12
  4. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 23:32
  5. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 07:50

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.