View Full Version : setText and html
mattia
17th December 2007, 11:08
Hello, if i have a QLabel i can do this:
ui.label->setText ( tr ( "<b><font color=red>Label</font></b>" ) );
and i see "Label" in red bold
instead of, if i have a QCheckBox i can't do this:
ui.checkBox->setText ( tr ( "<b><font color=red>Check box</font></b>" ) );
or better, i get no errors but it shows on the GUI
<b><font color=red>Check box</font></b>
and not "Check box" in red bold.
Any Ideas?
jacek
17th December 2007, 11:14
Checkboxes don't understand rich text. Set the font using QCheckBox::setFont() or use a style sheet.
mattia
17th December 2007, 11:25
this way is good for me:
QFont font(QFont::Bold);
ui.checkBox->setFont (font);
ui.checkBox->setText ( tr ( "text" ) );
but what shuld i do to set the red color?
thx
jacek
17th December 2007, 11:46
Use QPalette:
QPalette p( ui.checkBox->palette() );
...
ui.checkBox->setPalette( p );
mattia
17th December 2007, 11:56
i have to get the palette and change the color?
im not to skilled with this stuff...can you show me how to do it?
thx
jacek
17th December 2007, 12:07
I gave you 66% of the necessary code. See QPalette::ColorGroup.
mattia
17th December 2007, 12:59
I tried in this way
QPalette p( checkbox->palette() );
QColor c(Qt::red);
p.setColor(QPalette::Text,c);
checkbox->setPalette(p);
but nothing...why doesn't it work?
thx
jacek
17th December 2007, 13:08
why doesn't it work?
Look here:
http://doc.trolltech.com/4.3/images/palette.png
You should change the QPalette::WindowText colour.
mattia
28th January 2008, 16:09
Hi, with this code i correctly set bold-red text on checkbox but i have some problem to show it using gnome, i just get a bold-black text.
Any hint?
void setRichTextOnCheckBox ( QCheckBox * checkbox , QString message )
{
QFont font ("" , 9 , QFont::Bold );
checkbox->setFont( font );
QPalette p ( checkbox->palette() );
QColor c(Qt::red);
p.setColor(QPalette::WindowText,c);
checkbox->setPalette(p);
checkbox->setText( message );
}
jacek
28th January 2008, 21:41
Can you see the red text if you start your application with -style plastique switch? Do you use any stylesheets?
mattia
31st January 2008, 16:02
what the argument
-style plastique
should do?
thx
jacek
31st January 2008, 19:10
If will change the default style to Plastique.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.