3

I found that I can set a tooltip on a QLineEdit as such:

equation = new QLineEdit();
equation->setToolTip("Example: a*b+c+~c");

However, I would like the tooltip to be displayed when that QLineEdit is focused. How do I do that?

Thanks in advance.

Gezim
  • 7,112
  • 10
  • 62
  • 98
  • I'm getting there. I've got this so far: void EquationEditor::focusInEvent(QFocusEvent *e) { QHelpEvent event(QEvent::ToolTip, this->pos(), this->pos()); QApplication::sendEvent(this, &event); QLineEdit::focusInEvent(e); } But I'm not sure how to set the last two parameters to QHelpEvent. – Gezim Mar 02 '10 at 20:00

2 Answers2

1

I was able to accomplish this by subclassing QLineEdit and overriding focusInEvent(...) as such:

void EquationEditor::focusInEvent(QFocusEvent *e)
{
    QHelpEvent *event = new QHelpEvent(QEvent::ToolTip,
                                       QPoint(this->pos().x(), this->pos().y()),
                                       QPoint(QCursor::pos().x(), QCursor::pos().y()));  

    QApplication::postEvent(this, event);

    QLineEdit::focusInEvent(e);
}
Gezim
  • 7,112
  • 10
  • 62
  • 98
0

I would suggest that you have a look at the following example : Tool Tips Example

You could show the tooltip when your LineEdit is getting the focus, maybe by connecting to this signal:

void QApplication::focusChanged ( QWidget * old, QWidget * now )   [signal]

There is also some pretty neat informations about Focus here : QFocusEvent Class Reference

Hope it helps a bit !

Andy M
  • 5,945
  • 7
  • 51
  • 96