Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QGraphicsItem selection

Does a simple method exist to select part of a QGraphicsItem (like for a selection, with a dashed border for example), despite its position in the QGraphicsScene

I've found QGraphicsItem::ItemIsSelectable but it doesn't help me much.

Thx

like image 704
Matthieu Riegler Avatar asked Jan 20 '12 10:01

Matthieu Riegler


2 Answers

You can't select a part of QGraphicsItem. You can select whole item. Usualy it will draw a dashed rectangle around itself when selected.

You can select item by:

QGraphicsItem::setSelected

or

QGraphicsScene::setSelectionArea
like image 162
graphite Avatar answered Sep 21 '22 22:09

graphite


Do you want to select it when you're clicking on it? If yes, you can override the mousePressEvent(QGraphicsSceneMouseEvent event) listener for this item, and use setSelected(). In Java (sorry about it), it would be something like:

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

If you want to select it with a left button of course. :)

like image 35
Bertrand Moreau Avatar answered Sep 19 '22 22:09

Bertrand Moreau