PDA

View Full Version : Setting color in a QTreeWidget text



brevleq
9th August 2007, 20:48
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.

marcel
9th August 2007, 20:50
See QTreeWidgetItem::setForeground.

Regards

brevleq
10th August 2007, 17:41
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?

marcel
10th August 2007, 18:07
Well, do you have 6 columns in your tree widget?
Column count starts at 0.

Try:


item->setForeground(0,Qt::red);


I just tested it and it works.

regards

brevleq
10th August 2007, 20:21
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