2010-03-02 103 views
2

我发现我可以设置在QLineEdit的工具提示这样:示出在聚焦QLineEdit的工具提示的Qt中

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

然而,我想时QLineEdit的聚焦要显示的工具提示。 我该怎么做?

在此先感谢。

+0

我到达那里。 我有了这个迄今: 无效EquationEditor :: focusInEvent(QFocusEvent * E) { \t QHelpEvent事件(QEvent的工具提示::,这 - > POS(),这 - > POS()); QApplication :: sendEvent(this,&event); \t QLineEdit :: focusInEvent(e); } 但我不知道如何将最后两个参数设置为QHelpEvent。 – Gezim 2010-03-02 20:00:49

回答

1

我能够通过继承QLineEdit的和压倒一切的focusInEvent(...)这样来实现:

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

我建议你看看下面的例子:Tool Tips Example

您可以显示工具提示,当你LineEdit越来越关注的焦点,也许通过连接到该信号:

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

有这里还有一些非常整洁的信息:QFocusEvent Class Reference

希望它有所帮助!