我有一個從QGraphicsItem實現的類,名爲Node。如何獲得點擊QGraphicsItem事件,被通知focusOut
我有形「節點」的矩形,我可以做一些事情,當用戶在其上
我使用mousePress和mouseRelease事件點擊。
但我想通知用戶點擊「出」的矩形形狀。
我試圖實現這些功能:
的Qt代碼:
void Node::focusInEvent (QFocusEvent * event){
cout<<"in"<<endl;
update();
QGraphicsItem::focusInEvent(event);
}
void Node::focusOutEvent (QFocusEvent * event){
cout<<"out"<<endl;
update();
QGraphicsItem::focusOutEvent(event);
}
void Node::hoverEnterEvent(QGraphicsSceneHoverEvent *event){
cout<<"out"<<endl;
}
如果我或縮小矩形的點擊這些不反應。 我應該自己設置一個邏輯,例如獲取鼠標位置並控制它是否超出矩形? 還是有內置方法?
或「節點」對象如何知道是否單擊了其他節點對象?
我也想知道,使用Google搜索,但無法找到focusinevent和focusoutevent何時觸發?我猜focusOutEvent必須工作,當我點擊了項目,然後出了項目,我錯了嗎?
感謝您的想法。
非常感謝,我叫setFlags(ItemIsSelectable | ItemIsMovable | ItemIsFocusable);它的工作完美。但是,當我在另一個窗口中,然後單擊應用程序窗口時,focusin和focusout工作一次,我將搜索此內容。我在看之前看過文檔,但沒有看到我必須設置標誌。再次感謝 – merveotesi