Results 1 to 2 of 2

Thread: QTreeWidget itemClicked only on not selected items?

  1. #1
    Join Date
    Dec 2018
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QTreeWidget itemClicked only on not selected items?

    Hi there,

    i have a QTreeWidget with some QTreeWigetItems, wich i use as menu. I've implemented the on_treeWidget_itemClicked listener, so i can detect if i click on one of the QtreeWidgetItems inside my QTreeWidget.

    But how can i detect if the selected item is selected when i click on it, so that no action will be performed. One example to this:
    If i click on my item "LOAD" my custom code inside the on_treeWidget_itemClicked should only be executed if the item "LOAD" ist not selected when i click on it. When another item - let's say "SAVE" is selected and then i click on "LOAD" then my code should be executed.

    This should work, too, when i populate the QtreeWidget manually and set one item to selected, so that - let's say item "DYNAMIC" if manually added at runtime and set to setSelected(true) and then i click on this entry my code should not be executed.

    How can i do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,366
    Thanks
    36
    Thanked 1,537 Times in 1,488 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget itemClicked only on not selected items?

    Maybe you want to react to the "current item being changed" instead?

    If that alone is not good enough then store the current item in the respective change slot and check against the just clicked item in your click slot.
    Or react to selection change, store that and check against the old selection in your click handler slot

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Opa114 (5th January 2019)

Similar Threads

  1. Replies: 0
    Last Post: 21st October 2013, 09:16
  2. Replies: 1
    Last Post: 3rd January 2013, 13:11
  3. Replies: 3
    Last Post: 3rd January 2012, 23:44
  4. QTreeWidget fails to emit itemClicked signal.
    By avh in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2008, 18:49
  5. [QT4] Selected row in a QTreeWidget
    By vfernandez in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2006, 11:54

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.