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

Can't grab QGesture events from a QTreeWidget anymore

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.12.0
    • None
    • Android

    Description

      This very simple program used to work perfectly when using Qt 5.6 on Android, it now fails with Qt 5.12. On Windows, it works with both versions.

      It's very simple, just creating a helper to catch QGesture events and notify a specified class.

      *gesture.h*:

      #ifndef RMCWRAPPER_H
       #define RMCWRAPPER_H
      #include <QObject>
       #include <QPoint>
      class QWidget;
      class TapAndHoldWrapper : public QObject
       {
           Q_OBJECT
       public:
           TapAndHoldWrapper( QWidget* parent, QObject* receiver = NULL, const char* slot = NULL );
              ~TapAndHoldWrapper();
          bool eventFilter(QObject *obj, QEvent *event);
      signals:
           void requested( QPoint globalPos );
      private:
           QWidget* m_parent;
       };
      #endif
      

       

      *gesture.cpp*:

       

      #include "gesture.h"
       #include <QWidget>
       #include <QEvent>
       #include <QGestureEvent>
      TapAndHoldWrapper::TapAndHoldWrapper( QWidget* parent, QObject* receiver, const char* slot ) :
           QObject( parent ), m_parent( parent )
       {
           m_parent->installEventFilter( this );
           m_parent->grabGesture( Qt::TapAndHoldGesture );
           if ( receiver && slot )
               connect( this, SIGNAL(requested(QPoint)), receiver, slot );
       }
      TapAndHoldWrapper::~TapAndHoldWrapper()
       {
      }
      bool TapAndHoldWrapper::eventFilter(QObject *obj, QEvent *event)
       {
           if ( event->type() == QEvent::Gesture && obj == m_parent )
           {
               QGestureEvent *gestevent = static_cast<QGestureEvent *>(event);
               if (QGesture *gest = gestevent->gesture(Qt::TapAndHoldGesture))
               {
                   if ( gest && gest->state() == Qt::GestureFinished )
                       QPoint globalPos = gest->hotSpot().toPoint();
                                       emit requested( globalPos ); 
                                       return true;
                    }
                      }
               }
           // standard event processing
           return QObject::eventFilter(obj, event);
       }
      

      *mainwidget.h*:

       

      #ifndef MAINWIDGET_H
       #define MAINWIDGET_H
      #include <QMainWindow>
      class TapAndHoldWrapper;class MainWidget : public QMainWindow
       {
          Q_OBJECT 
      public:
          MainWidget(QWidget *parent = 0);
      public slots:
          void showMenu( QPoint pt ); private: TapAndHoldWrapper* helper;
      };
      #endif
      

       

      *mainwidget.cpp*:

       

      #include "mainwidget.h"
       #include "gesture.h"
      #include <QScreen>
       #include <QGuiApplication>
       #include <QTreeWidget>
       #include <QLabel>
       #include <QMessageBox>
      MainWidget::MainWidget(QWidget *parent)
          : QMainWindow(parent)
       {
           QTreeWidget* widget = new QTreeWidget(this); setCentralWidget(widget);
           helper = new TapAndHoldWrapper( widget, this, SLOT(showMenu(QPoint)) );
       }
      void MainWidget::showMenu( QPoint pt )
       {
           QMessageBox::information( this, "", "gesture detected" ); 
       }
      

       

      *main.cpp*:

       

      #include "mainwidget.h"
       #include <QApplication>
      int main(int argc, char *argv[])
       {
           QApplication app(argc, argv);
           MainWidget w; 
           w.show();
           return app.exec();
       }
      

      `TapAndHoldWrapper` used to catch the event and make `MainWidget::showMenu` be invoked. It does not anymore. It works perfectly when the `QMainWindow`'s central widget is a `QLabel`, but it fails when it's a `QTreeWidget`.

      The log reports this error (new in Qt 5.12):

      W/libqtbug_gesture.so(22735): QMetaObject::invokeMethod: No such method
      QTreeWidget::inputMethodQuery(Qt::InputMethodQuery,QVariant)

      Is there anything special that needs to be done for `QTreeWidget` to work smartly with gestures on Android with Qt 5.12? Is there somthing special to be done with input methods? I tried to call `widget->setInputMethodHints( Qt::InputMethodHint::ImhNone );` but it did not help...

      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
            jpo38 Jean Porcherot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes