PDA

View Full Version : How to set QLabel looks like QToolTip



topfortune
11th March 2012, 07:03
Hello,

I am creating a popup label, and I want it to be looking like a Tooltip. My platform is Win7 x64 Qt 4.7.4. Below is my code:


label->setPalette( QToolTip::palette() );

But when running, the label can not has a system tooltip looking. I attached 2 screenshots in this thread. One the label that looks like on my PC, another is the QToolTip image.

Anybody know what's wrong of my code? How can I set the QLabel to look like QToolTip? Thanks.


74847485

wysota
11th March 2012, 11:48
You can try with changing the window type to Qt::Tooltip however I don't think it will work. Why do you want to make a label look like a tooltip?

d_stranz
11th March 2012, 21:00
As it says in the docs, QToolTip uses the "Inactive" color group from the palette. QLabel probably uses the "Active" color group.

I do not know if the following would work, but you could try it:



QPalette pal( QToolTip::palette() );
pal.setColorGroup( QPalette::Inactive );
label->setPalette( pal );


But as Wysota asks, why do you want to make a label look like a tooltip? Why not just use QToolTip?

topfortune
12th March 2012, 14:30
Thanks to Wysota and d_stranz! Thank you for your reply.

I use the following code to set the QLabel, and also does not work.


QPalette pal = QToolTip::palette();
pal.setColor( label->backgroundRole(), pal.color( QPalette::Inactive, QPalette::ToolTipBase ) );
pal.setColor( label->foregroundRole(), pal.color( QPalette::Inactive, QPalette::ToolTipText ) );
label->setPalette( pal );

I want to make something like Code Parameters in Qt Creator (See the screenshot below). When the code parameters is displaying, the tooltip is still available when you hover on code.

7490

wysota
12th March 2012, 14:32
So why don't you use QToolTip::showText()?

topfortune
12th March 2012, 14:39
Sorry, Maybe I did not make it clear. When the code parameter is displaying, tooltip still need to be available when you hover on the code. Just Like in Qt Creator. See screenshot.

Is it possible to create an instance of QToolTip?

7491

wysota
12th March 2012, 16:09
Sorry, Maybe I did not make it clear. When the code parameter is displaying, tooltip still need to be available when you hover on the code. Just Like in Qt Creator. See screenshot.

Is it possible to create an instance of QToolTip?


Did you try using QToolTip::showText()?

topfortune
13th March 2012, 13:59
After looking into the QToolTip implement, I solve the problem. I moved the QTipLabel into my project.

Thank you!