Results 1 to 6 of 6

Thread: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6

  1. #1
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Text color of QTreeWidgetItem when item is selected - Qt 4.8.6

    Hi,

    I'm setting the text color of a particular QTreeWidgetItem using setForeground(). This works as long as the item is not selected. When the item is selected, the text color I've set is not respected.

    I've found another thread with the same question, unfortunately I don't understand how the OP fixed his issue.

    Help gladly appreciated!

    Franz

  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: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6

    In the referred post OP is re-implementing the paintEvent() function.

    If your case if it is just to change the foreground color, you could do it using below code, make sure to remove other palette changes you might have done.

    Qt Code:
    1. item->setForeground(column, QBrush(QColor(Qt::red)));
    To copy to clipboard, switch view to plain text mode 
    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
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6

    Thanks for your answer.

    If your case if it is just to change the foreground color, you could do it using below code, make sure to remove other palette changes you might have done.
    As I said in my question, that's exactly what I'm doing, and it works as long as the item is not selected. I'm looking for a way to change the color of the item when it's selected.

    Franz

  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: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6

    ok then you could use this
    Qt Code:
    1. treeWidget.setStyleSheet("QTreeWidget:item:selected:active { color: red }");
    To copy to clipboard, switch view to plain text mode 
    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
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6

    I thought about using stylesheets... But there is often a large number of items in that tree widget; can I "polish" items individually?

  6. #6
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6

    Santosh, what you propose is changing the text color of all selected items. As stated in my original question, this isn't what I'm after. I'm trying to change the text color of one or a few items. I succeed in doing so by using setForeground(), but this color isn't used when the item is selected.

    Any idea?

Similar Threads

  1. QTreeWidgetItem text color
    By Arthur in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2009, 17:59
  2. set color in QTreeWidgetItem text
    By mattia in forum Newbie
    Replies: 2
    Last Post: 7th January 2008, 10:06
  3. QTreeWidgetItem setting color for the text
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2007, 18:22
  4. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 08:09
  5. QListWidget/QTreeWidget, etc selected item color
    By Arthur in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2006, 17:50

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.