2015-05-20 18 views
0

我有一個Qt/cpp代碼並顯示子類型QLineEdit。雙擊QLineEdit時,將永遠不會調用focusInEvent(在Maya中啓動)。focusInEvent未在QLineEdit子類中調用

void myQLineEditClass::focusInEvent(QFocusEvent *e) 
{ 
    MGlobal::displayInfo(MQtUtil::toMString(QString().sprintf("HERE"))); 
    QLineEdit::focusInEvent(e); 
} 

這裏是永不顯示,事件如果focusInEvent出現在.H保護的一部分。任何想法如何獲得focusInEvents?

+0

您是否在焦點策略上設置了小部件? – cmannett85

+0

是的,要strongFocus –

+0

對我來說工作很好。 (不在Maya中) –

回答

0

該問題與QLineEdit位於另一個QGraphicsView中的QGraphicsView中有關。將QLineEdit引入更高級別的QGraphicsView使其工作。

1

請嘗試以下操作。在focusInEvent沒有的情況下,有幾次適用於我。

void YourWidget::changeEvent(QEvent* event) 
{ 
    if (event->type() == QEvent::ActivationChange) 
    { 
     if (isActiveWindow()) 
     { 
      // gaining the focus 
     } 
     else 
     { 
      // loosing the focus 
     } 
    } 

    // or whatever *parent* class call is 
    QWidget::changeEvent(event); 
} 
0

事件被編輯器小部件攔截。請參閱QItemDelegate::createEditor。那裏返回的小部件將得到它。