2010-03-02 102 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

希望它有所幫助!