Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Why does Overriding QuickWidget::mousePressEvent fail to pass mouse events to the parent widget?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 261 Views
  • 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.
  • M Offline
    M Offline
    mirro
    wrote on last edited by mirro
    #1
    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);
                 
                     }
          }
    };
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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 ?

      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