PDA

View Full Version : Change QTooltip color



pl01
23rd April 2012, 11:55
Hi,

I would like to change the QTooltip text color, I'm mainly working on a QStyle approach (and not a stylesheet base).
I have try the following, but no way :



QPalette pal = psApp.palette();
pal.setColor(QPalette::Inactive, QPalette::ToolTipBase, 0xa00000);
pal.setBrush(QPalette::Inactive, QPalette::ToolTipBase, QBrush(0xa00000));
pal.setColor(QPalette::Inactive, QPalette::ToolTipText, 0xa00000);
pal.setBrush(QPalette::Inactive, QPalette::ToolTipText, QBrush(0xa00000));
psApp.setPalette(pal);


I have try to find by browsing the original code... but no way !

d_stranz
23rd April 2012, 19:02
From the QPalette docs:


Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the Mac OS X styles.

I do not know if this is happening in your case.

Spitfire
25th April 2012, 10:31
It may be problem with Qt (using 4.6.3).

I say 'may' as I'm not sure, but it seems that palette is reset for some reason every time new tooltip is created.

This doesn't work:


void MainWindow::test( void ) //slot
{
QPalette p = QToolTip::palette();
p.setColor( QPalette::All, QPalette::ToolTipText, Qt::red );
QToolTip::setPalette( p );

QToolTip::showText( QPoint( 100, 100 ), "test", this );
}


But this does work:


void MainWindow::test( void ) //slot
{
QToolTip::showText( QPoint( 100, 100 ), "test", this );

QPalette p = QToolTip::palette();
p.setColor( QPalette::All, QPalette::ToolTipText, Qt::red );
QToolTip::setPalette( p );
}


Only thing that have changed is an order.
ToolTip palette is a static object so it should not matter when you set it but for some reason it does.
Maybe it will help you solve what's wrong.