2012-01-20 62 views
2

做一個簡單的方法,存在選擇的QGraphicsItem的部分(像一個選擇,與例如虛線邊框),儘管其在QGraphicsScene的QGraphicsItem選擇

位置,我發現QGraphicsItem::ItemIsSelectable但事實並非如此幫助我很多。

THX

回答

3

您不能選擇QGraphicsItem的一部分。您可以選擇整個項目。 Usualy將在選中時在其周圍繪製一個虛線矩形。

您可以通過選擇項目:

QGraphicsItem::setSelected 

QGraphicsScene::setSelectionArea 
2

你要選擇它,當你點擊它?如果是,則可以覆蓋此項目的mousePressEvent(QGraphicsSceneMouseEvent event)偵聽器,並使用setSelected()。如果你想與當然的左按鈕來選擇它

@Override 
public void mousePressEvent (QGraphicsSceneMouseEvent event) { 
    if (event.button() == Qt.MouseButton.LeftButton) { 
     this.setSelected(true); 
    } 
} 

:在Java(抱歉這件事),它會是這樣的。 :)