jeudi 12 novembre 2020

How to properly read touch events and get position on a QWidget Qt

I'm trying to develop a game controller for an android app in qt and am having some issues. The controller works perfectly fine when I just use QMouseEvents instead of QTouchEvents, but the problem is that it doesn't support multiple points of contact. There doesn't seem to be an equivalent for QWidget::mousePressEvent for touch events. I was told to use QWidget::event instead as such.

bool GameController::event(QEvent* event)
{
    switch(event->type())
    {
    case QEvent::TouchBegin: 
         //Do something...
         break;
    case QEvent::TouchEnd: 
         //Do something else...
         break;
    case QEvent::TouchUpdate:
         //Do something else...
         break;
    }
    return QWidget::event(event);
}

The problem with this is that I'm unable to use event->touchPoints() to get the position of the touches because it doesn't know that its a touch event. How can I properly read touch events?

Aucun commentaire:

Enregistrer un commentaire