views:

233

answers:

2

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.

A: 

Hey,

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
A: 

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);
}
Pilgrim