Results 1 to 6 of 6

Thread: Detect ONLY when a QTreeWidgetItem text has been edited.

  1. #1
    Join Date
    Aug 2012
    Posts
    10
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question Detect ONLY when a QTreeWidgetItem text has been edited.

    Hello,

    I've been searching the forum but didn't find any clue about the following doubt:

    I have a QTreeWidgetItem that I have made it editable:

    Qt Code:
    1. pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 

    If I use:

    Qt Code:
    1. connect(tree->treeWidget, SIGNAL(itemChanged( QTreeWidgetItem *, int)), (Tree*)tree, SLOT(foo()))
    To copy to clipboard, switch view to plain text mode 

    it detects not only when it has been edited, but also if its icon has changed.

    1) Is there an easy way to detect only when its text has been changed?

    2) The connect code that I use detects changes in any item of the tree. How can I make it to trigger only for a certain Item of the tree?


    Thank you in advance,

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Detect ONLY when a QTreeWidgetItem text has been edited.

    1) Is there an easy way to detect only when its text has been changed?

    2) The connect code that I use detects changes in any item of the tree. How can I make it to trigger only for a certain Item of the tree?
    Add parameters to slot foo() and inside the slot function check for the item and role
    Last edited by Santosh Reddy; 29th August 2013 at 21:45.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Aug 2012
    Posts
    10
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Detect ONLY when a QTreeWidgetItem text has been edited.

    Thanks for you answer,

    and how could I detect only when its text has been changed? Not a setIcon or something like that.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Detect ONLY when a QTreeWidgetItem text has been edited.

    when role == Qt::DisplayRole
    Last edited by Santosh Reddy; 30th August 2013 at 13:19.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Aug 2012
    Posts
    10
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Detect ONLY when a QTreeWidgetItem text has been edited.

    I dont use any model. Can I use a role in my case?

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Detect ONLY when a QTreeWidgetItem text has been edited.

    Oops, sorry my mistake.

    When using QTreeWidget it will not be possible. Any change will trigger the signal, filtering for text change is not possible.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Problem at getting text of QTreeWidgetItem
    By bienee in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2013, 19:52
  2. QTreeWidgetItem text color
    By Arthur in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2009, 17:59
  3. Custom controls when QTreeWidgetItem edited.
    By kubas in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2009, 11:27
  4. set color in QTreeWidgetItem text
    By mattia in forum Newbie
    Replies: 2
    Last Post: 7th January 2008, 10:06
  5. formatted text in QTreeWidgetItem
    By swiety in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2007, 17:26

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.