Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-123182

Pop-ups do not have proper touch/gesture support.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.15.12
    • None
    • Windows 10, Intel CPU
    • Windows

    Description

      Hello, I just came across an issue with touch events. I wanted to have my pop-ups (with Qt::Popup set) to receive touch events when I touch the screen. But I got mouse events instead.

      Accroding to the doc, "When the application opens a popup widget, all events are sent to the popup. " So I do expect touch events go to pop-up unconverted, and that could potentially make my code logic more consistent.

      Is it possible for pop-ups to receive proper touch events?

      Also, a reproducing example. I expect Label's text to say "Touch event ..." when touched, got "Mouse button pressed..." instead.

      Thank you in advance!

      #include <QApplication>  
      #include <QWidget>  
      #include <QPushButton>  
      #include <QLabel>
      #include <QEvent>
      #include <QMouseEvent>
      class Label : public QLabel  
      {  
      public:  
      	using QLabel::QLabel;
          bool event(QEvent* e) override  
          {  
              if (e->type() == QEvent::MouseButtonPress) {  
                  QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(e);  
                  setText("Mouse button pressed at (" + QString::number(mouseEvent->x()) + ", " + QString::number(mouseEvent->y()) + ")");  
                  return true;  
              }  
              else if (e->type() == QEvent::MouseButtonRelease) {  
                  QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(e);  
                  setText("Mouse button released at (" + QString::number(mouseEvent->x()) + ", " + QString::number(mouseEvent->y()) + ")");  
                  return true;  
              }  
              else if (e->type() == QEvent::TouchBegin) {  
                  QTouchEvent* touchEvent = static_cast<QTouchEvent*>(e);  
                  QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();  
                  QString touchText = "Touch event with " + QString::number(touchPoints.size()) + " touch points: ";  
                  for (const QTouchEvent::TouchPoint& touchPoint : touchPoints) {  
                      touchText += "ID: " + QString::number(touchPoint.id()) + " at (" + QString::number(touchPoint.pos().x()) + ", " + QString::number(touchPoint.pos().y()) + "); ";  
                  }  
                  setText(touchText);  
                  return true;  
              }  
              else if (e->type() == QEvent::TouchEnd) {  
                  QTouchEvent* touchEvent = static_cast<QTouchEvent*>(e);  
                  QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();  
                  setText("Touch event ended with " + QString::number(touchPoints.size()) + " touch points");  
                  return true;  
              }  
              return QLabel::event(e);  
          }  
      };
      
      int main(int argc, char *argv[])  
      {  
          QApplication app(argc, argv);  
      	app.setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false);
      	app.setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
          QWidget parent;  
          parent.resize(700, 700);  
        
          QPushButton popupButton("Open Popup", &parent);  
          popupButton.move(100, 80);  
        
          Label popupLabel("This is a Popup", &parent);  
          popupLabel.resize(700, 700);  
          popupLabel.setAlignment(Qt::AlignCenter);  
          popupLabel.setStyleSheet("background-color: white; border: 1px solid black;");  
          popupLabel.setWindowFlags(Qt::Popup);  
      	popupLabel. setAttribute(Qt::WA_AcceptTouchEvents);
          QObject::connect(&popupButton, &QPushButton::clicked, [&popupLabel]() {  
              popupLabel.show();  
          });  
        
          parent.show();  
        
          return app.exec();  
      }
       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            yangerhang 尔行 杨
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes