Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to set the backgroud color & font colr for LineEdit ToolTip
Indrajeet last edited by
How to set the backgroud color & font colr for LineEdit ToolTip?
I tried like this
QPalette palette = QToolTip::palette();
This ois working but it is applying colr for all tooltips.I want it to beapplied only for selected LineEdits.
the only way i see there is to install an eventfilter (or subclass QLineEdit) and listen to QHelpEvent of type QEvent::ToolTip. Prevent it from being further processed and display your QToolTip like you already did in your code. (See "tooltip example":http://qt-project.org/doc/qt-4.8/widgets-tooltips.html)
Before showing the tooltip you store it's palette and set it your palette (like you also already did). The problem now is only to figure out when the tool tip is close to reset the stored palette. This is only possible with busy polling and checking QToolTip::isVisible().... very ugly.
Thus i would recommend to subclass QLabel and override it's paintEvent() handler. Something like this:
MyToolTip::MyToolTip(QWidget* parent) : QLabel(parent)
this->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
this->setWindowOpacity(this->style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / 255.0);
this->layout()->setMargin(sthis->style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
void MyToolTip::paintEvent(QPaintEvent* event)