Cant Get Touch Inputs ın QPixMap(image) in QGraphicsView



  • I have a QScene object in QWidget and inside QWidget i have QGraphicsView. I convert images to QPixMap give it to QScene as an element and i defined touch events in QGraphicsView class. In QGraphicsView's creator method i enabled touch events with:

    @
    viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
    @

    and i am managing touch event by overriding ViewPortEvent method:

    @
    bool DicomView::viewportEvent(QEvent *event)

    {

    if(event->type() == QEvent::TouchBegin)
    
    {
    
        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
    
    
              .......
    

    return QGraphicsView::viewportEvent(event);

    }
    @

    PS:DicomView is type of QGraphicsView.

    My problem is when i run the application i can get the touch inputs from the view but when get to QView can not get touch inputs from QPixMap. I tried putting the methods inside QScene instead of QGraphicsView but QScene does not have a ViewPortEvent method. What am i supposed to do? I appreciate for the answers, thank you.

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • I try to read between the lines: are you trying to get those events in your QGraphicsItems or in your QGraphicsScene? If so, you need to use QGraphicsItem::setAcceptTouchEvents on your items, then you get the QTouchEvents in your QGraphicsItem::sceneEvent() override (or QGraphicsScene::event).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.