0

I need to show a "help text" when the mouse is over a pushbutton, I googled and I tried some code but in vain.

Can anyone correct it to me?

if (event->type() == QEvent::Enter)
{
    if (obj == q1)
    {
        iarm->printStatus("hi"); // For debugging
        QAction *newAct = new QAction(tr("&New"), this);
        newAct->setShortcut(tr("Ctrl+N"));
        newAct->setStatusTip(tr("Create a new file"));
        newAct->setWhatsThis(tr("Click this option to create a new file."));
    }
}
Bart
  • 19,692
  • 7
  • 68
  • 77

2 Answers2

1

Instead of going via the QAction, just use your QPushButton's (well, QWidget's really) setToolTip(const QString &).

That will set a tooltip for your button/widget which appears when your mouse hovers over it. It seems that is what you're going for, rather than the "What's This" message you're trying to use now.

Bart
  • 19,692
  • 7
  • 68
  • 77
1

You can use QpushButton's property setToolTip ( const QString & ) for the same. This will display your help text on mouse hovering over Qpushbutton.

For Smart text as per your requirement you can set stylesheet for Tooltip:-

QToolTip { color: #fff; background-color: #000; border: none; }

Nitish Jain
  • 206
  • 2
  • 5