Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Tablet Events in the Graphics View Framework

Tablet Events in the Graphics View Framework

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Soapbubble
    wrote on last edited by
    #1

    Hello,

    I am trying to develop a painting application controlled by a wacom tablet, so of course I need support for tablet events. I want to integrate the drawing canvas in the Qt's "Graphics" classes instead of plain QWidget because of the benefits of easy move, zoom, rotate transformations.
    The bad is that it seems the Graphics View Framework doesn't support tablet events by default, but my guess is I may be able to add the support by myself.
    The question is "how?".

    Should I install an event filter on the application, detect tablet events and try to integrate them in the framework?

    Should I subclass one of Graphics View Framework classes (like QGraphicsView, QGraphicsScene or QGraphicsWidget), capture every event before it is sent to my item in the scene, detect if the event is sent by the tablet (how?) and try to pack them in a QGraphicsSceneEvent subclass?

    I appreciate every help or hint.
    Thank you

    1 Reply Last reply
    0
    • S Offline
      S Offline
      srikanth_trulyit
      wrote on last edited by
      #2

      You can subclass QGraphicsView and check for QTabletEvent and send it to the corresponding item or scene as a custom event. As far as I know it is another kind of QEvent.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Soapbubble
        wrote on last edited by
        #3

        Thank you for you reply. Yes, this is what I have eventually done. It took me 4 steps:

        Subclass QGraphicsView - override event(QEvent *) method, detect tablet events and send them to the scene

        @
        bool MyGraphicsView::event(QEvent *event)
        {
        switch (event->type()){
        case QEvent::TabletPress:
        case QEvent::TabletRelease:
        case QEvent::TabletMove:
        QApplication::sendEvent(scene(), event);
        return true;
        default:
        return QGraphicsView::event(event);
        }
        }
        @

        Subclass QGraphicsScene, override event method, detect if the event is a tablet event

        @
        bool MyGraphicsScene::event(QEvent *event)
        {
        MyTabletEvent tabletEvent;
        switch(event->type()){
        case QEvent::TabletPress:
        case QEvent::TabletRelease:
        case QEvent::TabletMove:
        if (static_cast<QTabletEvent
        >(event)){
        tabletEvent = new MyTabletEvent(static_cast<QTabletEvent *>(event), someOtherArgs);
        sendEvent(itemAt(tabletEvent->scenePos()), tabletEvent);
        return true;
        }
        return false;
        default:
        return QGraphicsScene::event(event);
        }
        }
        @

        Subclass QGraphicsWidget, override event method, and detect mytabletevent

        @
        bool MyGraphicsWidget::event(QEvent *event)
        {
        switch(event->type()){
        case QEvent::TabletPress:
        case QEvent::TabletRelease:
        case QEvent::TabletMove:
        manageTabletEvent(static_cast<MyTabletEvent *>(event));
        return true;
        default:
        return QGraphicsWidget::event(event);
        }
        }
        @

        Create a custom event (MyTabletEvent) inherited from QTabletEvent which should be passed between the classes above. It should provied similar API to QGraphicsSceneEvent

        Actually this is where I am facing a new problem: how to map coordinates between view->scene->items.
        From view->scene I guess mapToScene(viewPos) it's OK, but from scene->items I don't exactly know what to do. Maybe someone helps me figure it out.
        Thanks

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved