3

I have a qtablewidget. There are certain cells (qtablewidgetitem) in this table that need to show error message via qtooltip. I wish to change the background color of tooltip of each cell so as to highlight the tooltip message better. How can it be done ?

Nishant Kumar
  • 363
  • 4
  • 20

2 Answers2

2

Probably the best way is the use of style sheets. You can set any text colors/background colors and text style that way.

Depending on your QT version, see the documentation:

Qt5 Style Sheet Documentation

meCHAoT
  • 336
  • 3
  • 9
  • 1
    Thanks a lot! Though an exhaustive one, the above documentation was of good help. I added following code to add customized tooltip to my qtablewidget => ui.ansTable->setStyleSheet("QToolTip{border: 2px solid orange; padding: 5px; border-radius: 3px; opacity: 200;}"); where ui.ansTable is a qtablewidget. – Nishant Kumar Dec 10 '15 at 09:32
2

you can use QtoolTip static methodes to update the palette :

QPalette palette = QToolTip::palette();
palette.setColor(QPalette::ToolTipBase,QColor("#F6F6F6")); // light grey
palette.setColor(QPalette::ToolTipText,QColor("#706F6F"));//dark grey for text
QToolTip::setPalette(palette);
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Nabil
  • 41
  • 3
  • 10