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. Detect Drag on Drop over all Child Widgets
Forum Updated to NodeBB v4.3 + New Features

Detect Drag on Drop over all Child Widgets

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 887 Views 2 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.
  • dporobicD Offline
    dporobicD Offline
    dporobic
    wrote on last edited by
    #1

    Hello,

    I'm trying to implement Drag and Drop behavior, across my whole application, I would like to execute some action when a drop occurs, no mater where in the Window . The Problem that I'm facing is that in my MainWindow, I have a Widget which contains a QGraphicsView, which again contains a QGraphicsScene, I can detect the drop anywhere in the application via EventFilter, except in the in the View and Scene. Is it possible to achieve some kind of global drag and drop behavior which I can detect from the MainWindow?

    Regards,
    Damir

    https://github.com/ksnip/ksnip

    1 Reply Last reply
    0
    • dporobicD Offline
      dporobicD Offline
      dporobic
      wrote on last edited by
      #6

      The issue was that the QGraphicsScene only accepts DragAndDrops over items, the solution for me was to overwrite the DragMoveEvent. I've posted my solution here https://stackoverflow.com/questions/61026334/detect-drag-on-drop-over-all-child-qwidgets/61073437#61073437

      https://github.com/ksnip/ksnip

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

        Hi,

        How did you setup the drag and drop part of your application ?

        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
        • dporobicD Offline
          dporobicD Offline
          dporobic
          wrote on last edited by
          #3

          Basically in my MainWindow I have this:

          void MainWindow::dropEvent(QDropEvent *event)
          {
          	auto pixmap = QPixmap(event->mimeData()->urls().first().toString().remove("file://"));
          	if(!pixmap.isNull()) {
          		load(pixmap);
          	}
          	
          	event->acceptProposedAction();
          }
          
          void MainWindow::dragEnterEvent(QDragEnterEvent *event)
          {
          	if (event->mimeData()->hasUrls()) {
          		event->acceptProposedAction();
          	}
          }
          

          This worked only when the drag and drop happens over the MainWindow, but not over the Child Widget that contains the View and Scene. So I tried installing an event filter but it didn't work:

          bool MainWindow::eventFilter(QObject *obj, QEvent *event)
          {
          	if(event->type() == QEvent::DragEnter) {
          		qDebug("Enter");
          	} else if(event->type() == QEvent::Drop) {
          		qDebug("Drop");
          	} else if(event->type() == QEvent::GraphicsSceneDrop) 	{
          		qDebug("Scene drop");
          	} else if (event->type() >= 159 && event->type() <= 168) {
          		qDebug("Any Scene Event");
          	}
          	return QObject::eventFilter(obj, event);
          }
          

          This was installed on my Child Widget in the MainWindow constructor:

                  ...
                  setAcceptDrops(true);
          	mChildWidget->installEventFilter(this);
          	mChildWidget->setAcceptDrops(true);
                  ...
          

          Didn't capture anything over the View/Scene

          https://github.com/ksnip/ksnip

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

            Standard view and scene ? How did you set them up ?

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

            dporobicD 1 Reply Last reply
            0
            • SGaistS SGaist

              Standard view and scene ? How did you set them up ?

              dporobicD Offline
              dporobicD Offline
              dporobic
              wrote on last edited by
              #5

              @SGaist Nothing special I guess, for both I have my own classes that inherit from the Qt ones.

              This is the Scene:
              https://github.com/ksnip/kImageAnnotator/blob/master/src/annotations/core/AnnotationArea.h
              https://github.com/ksnip/kImageAnnotator/blob/master/src/annotations/core/AnnotationArea.cpp

              This is the View:
              https://github.com/ksnip/kImageAnnotator/blob/master/src/gui/annotator/AnnotationView.h
              https://github.com/ksnip/kImageAnnotator/blob/master/src/gui/annotator/AnnotationView.cpp

              https://github.com/ksnip/ksnip

              1 Reply Last reply
              0
              • dporobicD Offline
                dporobicD Offline
                dporobic
                wrote on last edited by
                #6

                The issue was that the QGraphicsScene only accepts DragAndDrops over items, the solution for me was to overwrite the DragMoveEvent. I've posted my solution here https://stackoverflow.com/questions/61026334/detect-drag-on-drop-over-all-child-qwidgets/61073437#61073437

                https://github.com/ksnip/ksnip

                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