Results 1 to 3 of 3

Thread: How to change QToolTip color of a QPushbutton on Windows7

  1. #1
    Join Date
    Dec 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to change QToolTip color of a QPushbutton on Windows7

    Hello,

    I would like to change tooltip both front and background color of a QPushButton object. My environment is
    Windows7 Professional SP1 64bit, MSVC2008, Qt 4.7.2 (32bit).
    However with below code, I only see the effect of QToolTip::setFont(), but not ::setBrush() or ::setColor(). I vaguely remember that QToolTip on Windows XP and Windows 7 behaves differently. On Windows XP, QToolTip background and front colors are the same as the parent QPushButton. On Windows 7, QToolTip background and front colors are uniform for all QPushButton's and cannot be modified. In my case, the background color is light gray with gradient. And front color is white. These results a very LOW contrast. Would you please confirm this? Or would you please hint me to how to change them? Thanks a lot.

    Qt Code:
    1. QBrush brushToolTipBase(Qt::white);
    2. QBrush brushToolTipText(Qt::red);
    3. QPalette palette = QToolTip::palette();
    4. palette.setBrush(QPalette::Inactive, QPalette::ToolTipBase, brushToolTipBase);
    5. palette.setBrush(QPalette::Inactive, QPalette::ToolTipText, brushToolTipText);
    6. palette.setColor(QPalette::Inactive, QPalette::ToolTipBase, Qt::white);
    7. palette.setColor(QPalette::Inactive, QPalette::ToolTipText, Qt::red);
    8. QToolTip::setPalette(palette);QFont serifFont("Times", 14, QFont::Bold);
    9. QToolTip::setFont(serifFont);
    To copy to clipboard, switch view to plain text mode 

    Happy Holidays!
    casestudy

  2. #2
    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: How to change QToolTip color of a QPushbutton on Windows7

    Take a look here, maybe it will help you.
    If not you can always try to use rich text, for example:
    Qt Code:
    1. QPushButton* pb = new QPushButton("test", this);
    2. pb->setToolTip( "<span style=\"background-color:red;\">test</span>" );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change QToolTip color of a QPushbutton on Windows7

    Thanks a lot, Spitfire.
    Both methods worked! However on Windows7, the QToolTip background is OS determined. I can only alter the front/text color with both methods. By using rich text format, you get the illusion that the background color can be altered. In reality, "<span style=\"background-color:red;\">test</span>" changes the color of each character's pixel block to red, *NOT* the background color of the QToolTip frame. Nevertheless, it fits my need.

    It makes me wonder, why going through QPalette (as in my code example) would not work?!

    Happy New Year and Thank you again!

    Quote Originally Posted by Spitfire View Post
    Take a look here, maybe it will help you.
    If not you can always try to use rich text, for example:
    Qt Code:
    1. QPushButton* pb = new QPushButton("test", this);
    2. pb->setToolTip( "<span style=\"background-color:red;\">test</span>" );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Replies: 3
    Last Post: 22nd January 2010, 16:46
  3. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  4. How to change color of a QPushButton?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 13:22
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

Tags for this Thread

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.