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. Ending QDrag prematurely.

Ending QDrag prematurely.

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 4.6k 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.
  • B Offline
    B Offline
    ByteWight
    wrote on last edited by
    #1

    I want my application to accept the drag as a drop immediately as soon as the drag has entered. Is this possible?

    I have tried sending a QDropEvent to my widget on its dragEnterEvent() method, but the QDrag::exec() does not return anything (it doesn't count as a drop from the QDrag at all, I still see my pixmap and modified cursor).

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mehrdadsilver
      wrote on last edited by
      #2

      Did you use QGraphicsItem?

      Mehrdad Abdolghafari, Be silver

      1 Reply Last reply
      0
      • B Offline
        B Offline
        ByteWight
        wrote on last edited by
        #3

        No, I am using a QTabBar (I'm adding detachable tab functionality).

        If I find no solutions, I'm going to add a new thread with an event loop that simulates drag events.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thEClaw
          wrote on last edited by
          #4

          Have you tried posting a mouseReleaseEvent upon entering the widget? Or would that undermine your plans?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            ByteWight
            wrote on last edited by
            #5

            I tried and it didn't work. I tried with both sending the event to the widget and to the application's event processor with no avail.
            @
            QMouseEvent mouseEvent(QEvent::MouseButtonRelease, event->pos(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
            QCoreApplication::postEvent(static_cast<QObject*>(this), &mouseEvent, Qt::NormalEventPriority);@

            Anyone have any more suggestions?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thEClaw
              wrote on last edited by
              #6

              What code are you using to implement the drop? Nothing should stop you from you realizing it when the mouse enters (instead of later on). Does it work that far and the only step needed is to exit the drag-process?

              1 Reply Last reply
              0
              • B Offline
                B Offline
                ByteWight
                wrote on last edited by
                #7

                It does realize when the mouse enters. The problem is forcing it to stop.

                @QDrag drag = new QDrag(this);
                =QMimeData
                mimeData = new QMimeData();
                =mimeData->setData("tab-detach", QByteArray::number(clickIndex));
                drag->setMimeData(mimeData);

                switch(drag->exec(Qt::MoveAction | Qt::CopyAction))
                {
                case Qt::MoveAction:
                qDebug() << "Accepted";
                break;
                default:
                qDebug() << "Ignored";
                tabWidget->insertTab(position, dragWidget, dragText);
                tabWidget->setCurrentIndex(position);
                }@

                @
                void ResourceTabBar::dragEnterEvent(QDragEnterEvent *event)
                {
                QByteArray a = event->mimeData()->data("tab-detach");
                if (!a.isEmpty() && dragTab != nullptr)
                {
                qDebug() << dragTab;
                // This is where I've been trying to stop it.
                }
                QTabBar::dragEnterEvent(event);
                }@

                I can see the drag entered. I tried posting the code I posted previously to the comment in the latter code. I can make a dropEvent execute, but the drag->exec() does not end if I do.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thEClaw
                  wrote on last edited by
                  #8

                  What you are doing in case of something other than Qt::MoveAction is just reverting changes done before, I suppose?

                  Are you actually implementing the dropEvent() to have full control over it?

                  What happens if you call the base classes dropEvent() within the dragEnterEvent()? Something like the following:
                  @void QWidget::dragEnterEvent(QDragEnterEvent *event)
                  {
                  QWidget::dropEvent(event);//no calling of the "proper" base class implementation
                  }
                  @

                  If nothing works, I would try to just call "delete drag" once it is not needed anymore (reparent it first). I don't know if that causes a crash, or if the drag finishes in a clean manner.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    ByteWight
                    wrote on last edited by
                    #9

                    I handle the ignore, if necessary. The dropEvent simply accepts.

                    The code you provided did not do anything. Your idea does not work either. I tried to delete the drag on the qDrag::targetChanged signal and it does nothing at all.

                    I have tried checking the repository for the source and I cannot figure out how dragging works internally. What I do know is that on Windows (which is what platform I'm currently on), any events that I pass to QCoreApplication will be blocked until the QDrag exits. This is why I can't just post a drop event.

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      thEClaw
                      wrote on last edited by
                      #10

                      Have you tried calling QCoreApplication::processEvents() after posting the event?

                      The code I provided was just an example, you would have to make it fit to your class. Basically, you would have to replace the "QWidget" by the name of your class.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Sriu1
                        wrote on last edited by
                        #11

                        I'm facing the same issue.tried every suggestion mentioned in the previous comments.Anyone have any more suggestions?

                        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