Results 1 to 8 of 8

Thread: How to set QLabel looks like QToolTip

  1. #1
    Join Date
    Nov 2011
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to set QLabel looks like QToolTip

    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:

    Qt Code:
    1. label->setPalette( QToolTip::palette() );
    To copy to clipboard, switch view to plain text mode 

    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.


    p1.pngp2.png

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QLabel looks like QToolTip

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to set QLabel looks like QToolTip

    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:

    Qt Code:
    1. QPalette pal( QToolTip::palette() );
    2. pal.setColorGroup( QPalette::Inactive );
    3. label->setPalette( pal );
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Nov 2011
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set QLabel looks like QToolTip

    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.

    Qt Code:
    1. QPalette pal = QToolTip::palette();
    2. pal.setColor( label->backgroundRole(), pal.color( QPalette::Inactive, QPalette::ToolTipBase ) );
    3. pal.setColor( label->foregroundRole(), pal.color( QPalette::Inactive, QPalette::ToolTipText ) );
    4. label->setPalette( pal );
    To copy to clipboard, switch view to plain text mode 

    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.

    p3.png

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QLabel looks like QToolTip

    So why don't you use QToolTip::showText()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Nov 2011
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set QLabel looks like QToolTip

    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?

    p4.png
    Last edited by topfortune; 12th March 2012 at 13:45.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QLabel looks like QToolTip

    Quote Originally Posted by topfortune View Post
    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()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Nov 2011
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set QLabel looks like QToolTip

    After looking into the QToolTip implement, I solve the problem. I moved the QTipLabel into my project.

    Thank you!

Similar Threads

  1. QToolTip Qusetion
    By chandan in forum Newbie
    Replies: 1
    Last Post: 17th February 2011, 18:00
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. problem in QTooltip
    By wagmare in forum Qt Programming
    Replies: 8
    Last Post: 6th April 2009, 14:09
  4. QToolTip width
    By Vladimir in forum Qt Programming
    Replies: 7
    Last Post: 3rd March 2007, 08:15
  5. QToolTip
    By suresh in forum Newbie
    Replies: 7
    Last Post: 6th September 2006, 15:00

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.