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

Cannot receive dragLeave/dragMove events until dragEnter is accpeted on QTabWidget/QTabBar

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Invalid
    • Affects Version/s: 5.13.0
    • Fix Version/s: None
    • Component/s: GUI: Drag and Drop
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      I tried to implement an eventFilter for derived QTabWidget to catch DnD messages from its tabBar. dragEnter events is send nicely, but I do not receive dragLeave nor dragMove events until the dragEnter event has been accepted.

       

      QExtTabWidget::QExtTabWidget(QWidget *parent)
       : QTabWidget(parent)
      {
       // Need to set acceptdrops for tabBar explicitely, else dragEnter event is never sent
       // to the tabBar itself but only to owning QTabWidget. This leads to the problem that
       // dragEnter event is not sent as when the cursor has been already in the tab widget.
       // So dragging something from inside the tab widget (e.g. from a client widget) to the tab widget's
       // tabbar triggers no dragEnter event.
       this->tabBar()->setAcceptDrops(true);
      
       // install event filter to intercept events sent to this widgets tabbar
       this->tabBar()->installEventFilter(this);
      }
      
      bool QExtTabWidget::eventFilter( QObject *target, QEvent *event)
      {
       if ( !(target == this->tabBar()) )
         return false;
      
       if (event->type() == QEvent::DragEnter)
       {
        // need to accept the event, else QEvent::DragLeave and QEvent::DragMove won't be trigggered on the tabBar widget
        // and the code for dragMove and dragLeave below is never called
      
        QDragEnterEvent *dragEnterEvent = dynamic_cast<QDragEnterEvent*>(event);
        Q_ASSERT(dragEnterEvent != nullptr);
      
        // comment next line out to reproduce the issue
        dragEnterEvent->accept();
      
        qDebug() << event->type();
        return false;
       }
       else if ((event->type() == QEvent::DragLeave) || (event->type() == QEvent::Drop))
       {
        qDebug() << event->type();
        return false;
       }
       else if (event->type() == QEvent::DragMove)
       {
        qDebug() << event->type();
        return false;
       }
      
       return false;
      }
      

      dragEnter accept() switches the dragging cursor appearance too which is I do not want to. I think dragLeave and dragMove should be send/received independent of dragenter accept(). I aggree that possible drop event can depend on prior accept().

       

        Attachments

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

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            qt-knut Knut Beese
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes