Results 1 to 3 of 3

Thread: Change QTooltip color

  1. #1
    Join Date
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Change QTooltip color

    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 :

    Qt Code:
    1. QPalette pal = psApp.palette();
    2. pal.setColor(QPalette::Inactive, QPalette::ToolTipBase, 0xa00000);
    3. pal.setBrush(QPalette::Inactive, QPalette::ToolTipBase, QBrush(0xa00000));
    4. pal.setColor(QPalette::Inactive, QPalette::ToolTipText, 0xa00000);
    5. pal.setBrush(QPalette::Inactive, QPalette::ToolTipText, QBrush(0xa00000));
    6. psApp.setPalette(pal);
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    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: Change QTooltip color

    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.

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change QTooltip color

    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:
    Qt Code:
    1. void MainWindow::test( void ) //slot
    2. {
    3. QPalette p = QToolTip::palette();
    4. p.setColor( QPalette::All, QPalette::ToolTipText, Qt::red );
    5. QToolTip::setPalette( p );
    6.  
    7. QToolTip::showText( QPoint( 100, 100 ), "test", this );
    8. }
    To copy to clipboard, switch view to plain text mode 

    But this does work:
    Qt Code:
    1. void MainWindow::test( void ) //slot
    2. {
    3. QToolTip::showText( QPoint( 100, 100 ), "test", this );
    4.  
    5. QPalette p = QToolTip::palette();
    6. p.setColor( QPalette::All, QPalette::ToolTipText, Qt::red );
    7. QToolTip::setPalette( p );
    8. }
    To copy to clipboard, switch view to plain text mode 

    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.

  4. The following user says thank you to Spitfire for this useful post:

    d_stranz (26th April 2012)

Similar Threads

  1. How to change QToolTip color of a QPushbutton on Windows7
    By casestudy in forum Qt Programming
    Replies: 2
    Last Post: 22nd December 2011, 15:21
  2. Change in color map?
    By bigjoeystud in forum Qwt
    Replies: 4
    Last Post: 8th September 2010, 20:00
  3. Replies: 7
    Last Post: 1st March 2010, 17:49
  4. Replies: 3
    Last Post: 22nd January 2010, 16:46
  5. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25

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.