Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Propogate drag events to parent widget

Propogate drag events to parent widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 443 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.
  • Z Offline
    Z Offline
    zonman
    wrote on last edited by
    #1

    Hi everyone,
    I want to ask if there is way to propagate dragMoveEvents to parent widget? To receive any drag move events, you need to accpt event in dragEnterEvent. But if you accept this event in child widget, parent will not receive it. So how can I have similar flow like mouseMoveEvent and other, when at the end of these events you just propagate it to QWidget::mouseMoveEvent?
    I see only one option with eventFilter for child widget, but are there any other alternatives?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you explain your use case ? It's not really usual to have several widgets concerned by the same dragMoveEvent.
      That said, I think you are looking for the acceptProposedAction.

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

      Z 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Can you explain your use case ? It's not really usual to have several widgets concerned by the same dragMoveEvent.
        That said, I think you are looking for the acceptProposedAction.

        Z Offline
        Z Offline
        zonman
        wrote on last edited by
        #3

        Hi @SGaist, thanks for quick reply
        I have QScrollArea widget with list of custom widgets. I start drag in customWidget, by pressing mouse with ctrl. I want to implement custom AutoScrollArea, which make scroll when mouse is near top or bottom border. So I have dragndrop in that customWidgets and just want to receive dragMoveEvent in AutoScrollArea to change scroll bar position.
        I do not look at proposedAction, because not understand its idea. For example, I can set two action, like copy and move and in child widget accept only copy action, but move in AutoScrollArea?

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zonman
          wrote on last edited by
          #4

          So I made it by eventFilter for every customWidget, setting by AutoScrollArea, but maybe there is a better and simpler solution

          Methods declaration:

            bool eventFilter(QObject *watched, QEvent *event) override;
          
              void onDragEnterEvent(const QDragEnterEvent *event);
              void onDragMoveEvent(const QPoint &mousePos);
              void onDragLeaveEvent();
              void onDropEvent();
          

          EventFilter:

          bool AutoScrollArea::eventFilter(QObject *watched, QEvent *event)
          {
              if (event->type() == QEvent::DragEnter)
              {
                  QDragEnterEvent *dragEvent = dynamic_cast<QDragEnterEvent *>(event);
          
                  if (dragEvent != nullptr)
                      onDragEnterEvent(dragEvent);
              }
              else if (event->type() == QEvent::DragMove)
              {
                  QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent *>(event);
                  auto *watchedWidget = dynamic_cast<QWidget *>(watched);
          
                  if (watchedWidget != nullptr && dragEvent != nullptr)
                  {
                      const QPoint localMousePosition
                          = watchedWidget->mapTo(this, dragEvent->position().toPoint());
          
                      onDragMoveEvent(localMousePosition);
                  }
              }
              else if (event->type() == QEvent::DragLeave)
              {
                  QDragLeaveEvent *dragEvent = static_cast<QDragLeaveEvent *>(event);
          
                  if (dragEvent != nullptr)
                      onDragLeaveEvent();
              }
              else if (event->type() == QEvent::Drop)
              {
                  QDropEvent *dropEvent = static_cast<QDropEvent *>(event);
          
                  if (dropEvent != nullptr)
                      onDropEvent();
              }
          
              return QWidget::eventFilter(watched, event);
          }
          
          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