Results 1 to 3 of 3

Thread: QTreeWidgetItem text color

  1. #1
    Join Date
    Jan 2006
    Location
    Leiden, the Netherlands
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidgetItem text color

    Hello,

    Using Qt 4.4.1, Windows

    I have a QTreeWidget, with items that can have other colors than standard.

    When an item is NOT selected, it works perfectly. When an item is selected, it does not. If the tree does not have the focus, the selected item also does not have the color I want.

    This is a sample of the Paint function in my tree item delegate: None of the palette settings (In this sample QPalette:All, but any other setting also gives the result) work.

    It doesn't matter if I give the tree item a different color or change text and foreground color of the treeItem: when an item is the current item, it is White (when highlighted) or Black when the tree does not have the focus...

    Qt Code:
    1. QColor dirtyColor = Qt::red
    2. QPalette p = pTree->palette();
    3. QPalette old_palette = p;
    4. p.setColor(QPalette::All, QPalette::Text, dirtyColor);
    5. p.setColor(QPalette::All, QPalette::HighlightedText, dirtyColor);
    6. p.setColor(QPalette::All, QPalette::BrightText, dirtyColor);
    7.  
    8. pTree->setPalette(p);
    9.  
    10. pItem->setTextColor(index.column(), dirtyColor);
    11. pItem->setForeground(index.column(), dirtyColor);
    12.  
    13. QItemDelegate::paint(painter, option, index);
    14. pTree->setPalette(old_palette);
    To copy to clipboard, switch view to plain text mode 

    Does anyone know what to do?

  2. #2
    Join Date
    Jan 2006
    Location
    Leiden, the Netherlands
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem text color

    Changing QStyleOptionViewItem worked...

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidgetItem text color

    Didn't QTreeWidgetItem::setForeground() suit your needs?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. set color in QTreeWidgetItem text
    By mattia in forum Newbie
    Replies: 2
    Last Post: 7th January 2008, 09:06
  3. Setting a highlight text color for QTableWidgetItem
    By Hiba in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2007, 10:51
  4. QTreeWidgetItem setting color for the text
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2007, 17:22
  5. Setting text color on QLabel
    By Yorma in forum Newbie
    Replies: 11
    Last Post: 15th June 2006, 07:25

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.