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. QGroupBox dropEvent never called
Qt 6.11 is out! See what's new in the release blog

QGroupBox dropEvent never called

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 944 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.
  • S Offline
    S Offline
    SebastianS
    wrote on last edited by
    #1

    Hey guys,

    I try to drop a widget on a QGroupBox. For that purpose, I installed a event filter in the containing widget:

    QGroupBox *gTemp = new QGroupBox("shift" + QString::number(i + 1), this);
            gTemp->setFlat(true);
            gTemp->setAcceptDrops(true);
            gTemp->installEventFilter(this);
    

    The code of the event filter is as follows:

    bool Fachbereich::eventFilter(QObject *object, QEvent *event)
    {
        qDebug() << "Fachbereich::eventFilter(" << object << ", " << event << ")";
    
        if (event->type() == QEvent::Drop)
        {
            QGroupBox *gTemp = qobject_cast<QGroupBox*>(object);
            qDebug() << gTemp->title();
        }
    
        return QObject::eventFilter(object, event);
    }
    
    

    The QGroupBox's DragEnterEvent works, as the output of qDebug() shows:

    Fachbereich::eventFilter( QGroupBox(0x3335a8e0) ,  QDragEnterEvent(dropAction=MoveAction, proposedAction=MoveAction, possibleActions=MoveAction, posF=7,53, answerRect=QRect(7,53 1x1), formats=("text/plain"), LeftButton )
    

    The QDropEvent on the other hand is never called. Do you have any suggestions?

    Thanks
    Sebastian

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SebastianS
      wrote on last edited by SebastianS
      #2

      Ok, solved the "problem". I just derived my own class of QGroupBox. Here is the code, just in case it can help somebody facing the same ideas.

      dropablegroupbox.h

      #ifndef DROPABLEGROUBOX_H
      #define DROPABLEGROUBOX_H
      
      #include <QGroupBox>
      
      class DropableGrouBox : public QGroupBox
      {
      public:
          DropableGrouBox(const QString &title);
      
      private:
          void dragEnterEvent(QDragEnterEvent *event);
          void dragMoveEvent(QDragMoveEvent *event);
          void dropEvent(QDropEvent *event);
      };
      
      #endif // DROPABLEGROUBOX_H
      

      dropablegroupbox.cpp

      #include "dropablegroubox.h"
      #include <QDebug>
      #include <QDragEnterEvent>
      #include <QDropEvent>
      #include <QMimeData>
      
      DropableGrouBox::DropableGrouBox(const QString &title)
      {
          QGroupBox::setTitle(title);
          setAcceptDrops(true);
      }
      
      void DropableGrouBox::dragEnterEvent(QDragEnterEvent *event)
      {
          qDebug() << "DropableGrouBox::dragEnterEvent(" << event << ")";
      
          if (event->mimeData()->hasFormat("text/plain"))
          {
                  event->acceptProposedAction();
          }
      }
      
      void DropableGrouBox::dragMoveEvent(QDragMoveEvent *event)
      {
          qDebug() << "DropableGrouBox::dragMoveEvent(" << event << ")";
      
          if (event->mimeData()->hasFormat("text/plain"))
          {
                  event->acceptProposedAction();
          }
      }
      
      void DropableGrouBox::dropEvent(QDropEvent *event)
      {
          qDebug() << "DropableGrouBox::dropEvent(" << event << ")";
      
          QString ID = event->mimeData()->text();
      
          if (ID.toInt() != 0)
          {
              event->acceptProposedAction();
          }
      }
      

      In the code:

      DropableGrouBox *gTemp = new DropableGrouBox("Schicht " + QString::number(i + 1));
              gTemp->setFlat(true);
              gTemp->setAcceptDrops(true);
      

      Best regards
      Sebastian
      https://www.five-s.de

      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