Results 1 to 5 of 5

Thread: Setting color in a QTreeWidget text

  1. #1
    Join Date
    Aug 2007
    Posts
    64
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Setting color in a QTreeWidget text

    Hey guys, how can I change the color of a text in a QTreeWidget??
    I want some lines displayed in red, I used:

    void QWidget::setForegroundRole ( QPalette::ColorRole role )

    but nothing happened!
    I'm using Qt-4.3 in linux.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting color in a QTreeWidget text


  3. #3
    Join Date
    Aug 2007
    Posts
    64
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting color in a QTreeWidget text

    Thanks but...

    I put this in the code:

    if (credito_radio->isChecked()){
    QBrush brush;
    brush.setColor(Qt::red);
    item->setForeground(5,brush);
    saldo_doubleSpin->setValue(saldo_doubleSpin->value()+valor_doubleSpin->value());
    aux.setNum(1,10);
    item->setText(5,aux);
    }

    but the text still in black!!
    I'm doing something wrong?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting color in a QTreeWidget text

    Well, do you have 6 columns in your tree widget?
    Column count starts at 0.

    Try:
    Qt Code:
    1. item->setForeground(0,Qt::red);
    To copy to clipboard, switch view to plain text mode 

    I just tested it and it works.

    regards

  5. #5
    Join Date
    Aug 2007
    Posts
    64
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Setting color in a QTreeWidget text

    Ohh guy, thank you:

    Well, do you have 6 columns in your tree widget?
    Column count starts at 0.

    after you said it I reviewed the code and I could see, the column 5 isn't visible!! I was doing the setForeground in the wrong column!! hehe

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Replies: 2
    Last Post: 23rd July 2012, 08:42
  3. setting data of buffer to QTreeWidget column
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 17:12
  4. setting QTreeWidget vertical labels
    By hyling in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 18:53
  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.