1

I have a main widget in Qt and this widget contains a QGraphicsView and inside it QGraphicsScene. In scene I add QGraphicsPixmapItems and QGraphicsTextItems. In main widget I handle QWidget::mouseDoubleClickEvent ( QMouseEvent * event ), my items are all set flags with:

mItem->setFlag ( QGraphicsItem::ItemIsMovable );
mItem->setFlag ( QGraphicsItem::ItemIsSelectable );
mItem->setFlag ( QGraphicsItem::ItemIsFocusable);

Because I want to move items in scene and select them and also I want when double click occurs main widget handles that. When I double click onto QGraphicsTextItem it enters to mouseDoubleClickEvent in main widget, however when I double click to QGraphicsPixmap item, it absorbs double click and does not send it to main widget. Also when ItemIsFocusable flag is not set, QGraphicsTextItem also does absorb the double click event. Why does it occur?.
I did not want to implement subclass of QGraphicsItems and wanted to use already defined methods. Here is a picture of what I do:

enter image description here

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Akın Yılmaz
  • 300
  • 5
  • 18
  • A textual description of what you think your code is doing may be rather different from what it actually does. I suggest posting an example of your code in order to improve the question. – TheDarkKnight Mar 03 '16 at 16:31
  • What do you expect the `QGraphicsPixmapItem` to do on double click ? Items do their default implementation: Unless you subclass them and do your own implementation. – Thalia Mar 03 '16 at 21:55

1 Answers1

2

I found a solution for this because my QGraphicsPixmapItem and QGraphicsTextItem behaves differently on double clicking: QGraphicsTextItem sends its double click event to parent while QGraphicsPixmapItem does not, I commented out the ItemIsFocusable property :

mItem->setFlag ( QGraphicsItem::ItemIsMovable );
mItem->setFlag ( QGraphicsItem::ItemIsSelectable );
//mItem->setFlag ( QGraphicsItem::ItemIsFocusable);

Because even if ItemIsFocusable is a QGraphicsItem property, it does not behave same in different QGraphicsItem inherited classes, so for handling double click I installed an event filter on QGraphicsScene that contains QGraphicsItems in main widget.

this->ui.graphicsViewMainScreen->scene ( )->installEventFilter ( this );

And as implementation of event filter :

bool MyMainWidget::eventFilter ( QObject *target , QEvent *event )
{
    if ( target == this->ui.graphicsViewMainScreen->scene ( ) )
    {
        if ( event->type ( ) == QEvent::GraphicsSceneMouseDoubleClick )
        {
            QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>( event );
        }
    }
    return false;
}

Now I can detect double clicks on QGraphicsItems on my main widget's scene.

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Akın Yılmaz
  • 300
  • 5
  • 18