做一個簡單的方法,存在選擇的QGraphicsItem的部分(像一個選擇,與例如虛線邊框),儘管其在QGraphicsScene
的QGraphicsItem選擇
位置,我發現QGraphicsItem::ItemIsSelectable
但事實並非如此幫助我很多。
THX
做一個簡單的方法,存在選擇的QGraphicsItem的部分(像一個選擇,與例如虛線邊框),儘管其在QGraphicsScene
的QGraphicsItem選擇
位置,我發現QGraphicsItem::ItemIsSelectable
但事實並非如此幫助我很多。
THX
您不能選擇QGraphicsItem的一部分。您可以選擇整個項目。 Usualy將在選中時在其周圍繪製一個虛線矩形。
您可以通過選擇項目:
QGraphicsItem::setSelected
或
QGraphicsScene::setSelectionArea
你可以打電話QGraphicsScene::setSelectionArea(QPainter path, QTransform),後來通過調用selectionArea檢索區域。但是,如果你想檢索當前正在選擇的項目,你只會得到整個QGraphicsItems。
你要選擇它,當你點擊它?如果是,則可以覆蓋此項目的mousePressEvent(QGraphicsSceneMouseEvent event)
偵聽器,並使用setSelected()
。如果你想與當然的左按鈕來選擇它
@Override
public void mousePressEvent (QGraphicsSceneMouseEvent event) {
if (event.button() == Qt.MouseButton.LeftButton) {
this.setSelected(true);
}
}
:在Java(抱歉這件事),它會是這樣的。 :)