Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. handle mouse events for touchscreen use

handle mouse events for touchscreen use

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 609 Views 1 Watching
  • 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.
  • JasurammeJ Offline
    JasurammeJ Offline
    Jasuramme
    wrote on last edited by
    #1

    Good day, all!
    I have touchscreen on device I program for.
    And there are some issues, when I press the screen with fingers. Sometimes it generates few wrong clicks.
    So I try to handle these first clicks with global eventFilter. First few clicks it forbids to process mousePress event. And after some time, it allows to do it.

    I have some problem there.
    So, lets say, user click on point outside the button and later on move finger in, I post mousePress event and mouseRelease event straight away. mousePress achive button, but mouseRelease doesn't! So button is always on after that. What would stop button to receive mouseRelease? I thought, that some enter events, but it's not.
    Advice me please, if you can, what could cause it.

    There is some code:

    function to send press event back to application

    void MainWindow::sendCLick(int x, int y){
        QPoint qp = QPoint(x,y);
        QWidget *QW = qApp->widgetAt(qp);
        if (QW){
            clickSent=1;
            QPoint qp1=QW->mapFromGlobal(qp);
            QMouseEvent* evt1 = new QMouseEvent(QEvent::MouseButtonPress,
                                            qp1,
                                            qp,
                                            Qt::LeftButton,
                                            Qt::LeftButton,
                                            Qt::NoModifier);
            QCoreApplication::postEvent(QW,evt1);
        }
    }
    

    function to send release event

    void MainWindow::sendRelease(int x, int y){
        QPoint qp = QPoint(x,y);
        QWidget *QW = qApp->widgetAt(qp);
        if (QW){
            QPoint qp1=QW->mapFromGlobal(qp);
            QMouseEvent* evt1 = new QMouseEvent(QEvent::MouseButtonRelease,
                                            qp1,
                                            qp,
                                            Qt::LeftButton,
                                            Qt::LeftButton,
                                            Qt::NoModifier);
       }
    }
    
    

    There is my global event filter

    bool MainWindow::eventFilter(QObject *obj, QEvent *evt){
        if (evt->type()==QEvent::MouseButtonPress){
            if (clickSent){
                clickSent=0;
                QPoint qp=QCursor::pos();
                sendRelease(qp.rx(),qp.ry());
                return QMainWindow::eventFilter(obj,evt);
            }
    
            if (!clickedOn){
                timeAfterClick=0;
                QPoint pos=QCursor::pos();
                pseudoMouseX=pos.rx();
                pseudoMouseY=pos.ry();
                clickedOn=1;
            }
            return true;
    
        }
    
        if (evt->type()==QEvent::MouseButtonRelease){
            if ((!QApplication::mouseButtons())&&clickedOn){
                clickedOn=0;
            }
        }
        return QMainWindow::eventFilter(obj,evt);
    }
    

    And after some time I sent these events by timer

    pseudoMouseX=CCur.rx();
    pseudoMouseY=CCur.ry();
    timeAfterClick++;
    if (timeAfterClick>10){
        timeAfterClick=1;
        clickSent=1;
        sendCLick(pseudoMouseX,pseudoMouseY);
        sendRelease(pseudoMouseX,pseudoMouseY);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Something's not clear here, why do you need to generate your own mouse event ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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