Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why does Overriding QuickWidget::mousePressEvent fail to pass mouse events to the parent widget?



  • class cusQQuickWidget:public QuickWidget{
    Q_OBJECT
    public:
         cusQQuickWidget(QWidget* parent = nullptr):QuickWidget(parent){}
         virtual ~cusQQuickWidget(){}
    protected:
         void mousePressEvent(QMouseEvent* p)
         {
                 if (this->parentWidget())
                     {
                 
                         //this->setAttribute(Qt::WA_TransparentForMouseEvents, true);
                 
                         QPoint pt = this->mapTo(this->parentWidget(), e->pos());
                 
                         QWidget *w = this->parentWidget()->childAt(pt);
                 
                         if (w)   
                         {
                 
                             pt = w->mapFrom(this->parentWidget(), pt);
                 
                             QMouseEvent *event = new QMouseEvent(e->type(), pt, e->button(), e->buttons(), e->modifiers());
                 
                             QApplication::postEvent(w, event);
                 
                         }
                         //this->setAttribute(Qt::WA_TransparentForMouseEvents, false);
                 
                     }
          }
    };

  • Lifetime Qt Champion

    Hi
    By parent widget, you mean the Mainwindow/where the QuickWidget is placed ?

    You seem to try to forward a an event.

    But it makes little sense to me as I dont understand what you could use that for.

    Do you try to know in MainWindow if QuickWidget was clicked ?


Log in to reply