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. Capture drag and drop events when moving QDockWidget
Forum Updated to NodeBB v4.3 + New Features

Capture drag and drop events when moving QDockWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k 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.
  • A Offline
    A Offline
    ASxa86
    wrote on last edited by
    #1

    I'm attempting to create a system where I can drag and drop QDockWidgets into a central QTabWidget.

    Unfortunately I've hit a road block. Is there a way to capture the drag/drop events from moving a QDockWidget within my QTabWidget. I haven't had any success.

    Obviously, QMainWindow is able to recognize QDockWidgets. I need to write a QTabWidget to do the same.

    Edit: Below is my simple attempt at trying to catch the drop event in my debugger.

    @
    // My simple main window for testing.
    FormMain::FormMain(QWidget* parent) : QMainWindow(parent)
    {
    this->setGeometry(80, 80, 800, 600);

     auto wTab = new TabWidget();
    
     auto wLeftDock = new QDockWidget();
     wLeftDock->setStyleSheet("background-color:red");
    
     auto wRightDock = new QDockWidget();
     wRightDock->setStyleSheet("background-color:blue");
    
     auto wTopDock = new QDockWidget();
     wTopDock->setStyleSheet("background-color:green");
    
     auto wBottomDock = new QDockWidget();
     wBottomDock->setStyleSheet("background-color:yellow");
    
     this->setCentralWidget(wTab);
     this->addDockWidget(Qt::LeftDockWidgetArea, wLeftDock);
     this->addDockWidget(Qt::RightDockWidgetArea, wRightDock);
     this->addDockWidget(Qt::TopDockWidgetArea, wTopDock);
     this->addDockWidget(Qt::BottomDockWidgetArea, wBottomDock);
    

    }

    // My simple tab widget for testing
    TabWidget::TabWidget(QWidget* parent) : QTabWidget(parent)
    {
    this->setAcceptDrops(true);
    this->installEventFilter(this);
    }

    void TabWidget::dragEnterEvent(QDragEnterEvent* event)
    {
    // Break point here.
    event->acceptProposedAction();
    }

    void TabWidget::dropEvent(QDropEvent* event)
    {
    // Break point here.
    event->acceptProposedAction();
    }

    bool TabWidget::eventFilter(QObject* obj, QEvent* event)
    {

     if(event->type() == QEvent::Type::MouseButtonRelease)
     {
                // Break point here.
          auto dummy = 2 + 3;
     }
    
     return this->QTabWidget::eventFilter(obj, event);
    

    }
    @

    None of my break points are hit when I attempt to drag a QDockWidget from it's docked location to the center tab widget.

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

      Hi,

      What did you try ?

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ASxa86
        wrote on last edited by
        #3

        Sorry, updated my post with my test code.

        My idea is to drag a qdockwidget over to a qtabwidget and when a drop event occurs, set the contents of the qdockwidget into a new tab on the qtabwidget.

        Then, i also want to be able to drag a "tab" from the tab widget which will immediately convert it back to a qdockwidget which can then be dropped back into a docking location on the qmainwindow.

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

          The drag and drop of QDockWidgets is specially handled in QMainWindow so you won't have any drop in your QTableView from it. You'd need to take a look at QMainWindow source code to replicate the functionality

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ASxa86
            wrote on last edited by
            #5

            That's what I figured I'd have to do. Thank you.

            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