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. What enum Qt::DropAction really do?

What enum Qt::DropAction really do?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.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.
  • Q Offline
    Q Offline
    qwe3
    wrote on last edited by qwe3
    #3

    @jsulm Is that enum Qt::DropAction only to return in drag->exec() in a nice form? Not a number like 1,2,3, but Qt::DropAction::Move, Qt::DropAction::Copy etc ?

    Or in some function ( like event->setDropAction() ) really do something with dragged data?

    I don't see a difference:

    drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::LinkAction) 
    drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::TargetMoveAction) 
    drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) 
    

    For me Qt::CopyAction is only number, which is returned from drag->exec().

    For me in docs we can change:

    Qt::CopyAction	0x1	Copy the data to the target.
    Qt::MoveAction	0x2	Move the data from the source to the target.
    

    To:

    Qt::CopyAction	0x2	Move the data from the source to the target.
    Qt::MoveAction	0x1	Copy the data to the target.
    

    And it still be ok.

    jsulmJ 1 Reply Last reply
    0
    • Q qwe3

      @jsulm Is that enum Qt::DropAction only to return in drag->exec() in a nice form? Not a number like 1,2,3, but Qt::DropAction::Move, Qt::DropAction::Copy etc ?

      Or in some function ( like event->setDropAction() ) really do something with dragged data?

      I don't see a difference:

      drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::LinkAction) 
      drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::TargetMoveAction) 
      drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) 
      

      For me Qt::CopyAction is only number, which is returned from drag->exec().

      For me in docs we can change:

      Qt::CopyAction	0x1	Copy the data to the target.
      Qt::MoveAction	0x2	Move the data from the source to the target.
      

      To:

      Qt::CopyAction	0x2	Move the data from the source to the target.
      Qt::MoveAction	0x1	Copy the data to the target.
      

      And it still be ok.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @qwe3 It is explained in the documentation (https://doc.qt.io/qt-5/qdrag.html#exec-1):
      "The drop actions that the user can choose from are specified in supportedActions."
      Second parameter: "The defaultDropAction determines which action will be proposed when the user performs a drag without using modifier keys."

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        qwe3
        wrote on last edited by
        #5

        @jsulm Yes. And I set in defaultDropAction for example Qt::LinkAction. And run example app. Next I set as a defaultDropAction, Qt::TargetMoveAction ). And run example app. And I don't see a difference.

        And if I will be a programmer, which works in QT Company and I will add to enum Qt::DropAction for example Qt::abcdef and set in defaultDropAction that Qt::abcdef effect in this example app will be the same.

        So there is any difference in setting Qt::LinkAction and Qt::CopyAction? Or this is just a name?

        jsulmJ 1 Reply Last reply
        0
        • Q qwe3

          @jsulm Yes. And I set in defaultDropAction for example Qt::LinkAction. And run example app. Next I set as a defaultDropAction, Qt::TargetMoveAction ). And run example app. And I don't see a difference.

          And if I will be a programmer, which works in QT Company and I will add to enum Qt::DropAction for example Qt::abcdef and set in defaultDropAction that Qt::abcdef effect in this example app will be the same.

          So there is any difference in setting Qt::LinkAction and Qt::CopyAction? Or this is just a name?

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @qwe3 Second parameter: "The defaultDropAction determines which action will be proposed when the user performs a drag without using modifier keys.". So, the second parameter specifies what exec() will return if user does not use modifier key. Like in this example: https://doc.qt.io/qt-5/qtwidgets-draganddrop-fridgemagnets-example.html

          if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction)
              child->close();
          else
              child->show();
          

          In this example, if user does not use modifier key CopyAction will be returned by exec(), else MoveAction.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • Q Offline
            Q Offline
            qwe3
            wrote on last edited by
            #7

            @jsulm Drag move events occur when the cursor enters a widget, when it moves within the widget, and when a modifier key is pressed on the keyboard while the widget has focus.

            I understand "Drag move events occur when the cursor enters a widget, when it moves within the widget", but I don't understand "and when a modifier key is pressed on the keyboard while the widget has focus". I don't use keyboard when run this fridge magnets app ( only mouse ).

            jsulmJ 1 Reply Last reply
            0
            • Q qwe3

              @jsulm Drag move events occur when the cursor enters a widget, when it moves within the widget, and when a modifier key is pressed on the keyboard while the widget has focus.

              I understand "Drag move events occur when the cursor enters a widget, when it moves within the widget", but I don't understand "and when a modifier key is pressed on the keyboard while the widget has focus". I don't use keyboard when run this fridge magnets app ( only mouse ).

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @qwe3 said in What enum Qt::DropAction really do?:

              I don't use keyboard when run this fridge magnets app ( only mouse )

              You don't have to use it, but you can...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                qwe3
                wrote on last edited by
                #9

                @jsulm I know I have many questions, but I would like to really understand this drag and drop. So most important for me question:
                for example I have to create simple project when I have big widget and many labels on it. If I drag and drop any label I have to change only it position ( no copy ). So when I started with 10 labels, at the end of app run I will have still 10 labels. So I can use:

                if ((drag->exec(Qt::CopyAction, Qt::CopyAction ) == Qt::CopyAction )
                {
                    // moveThatLabel
                }
                

                So I will use only Qt::CopyAction value in application, where I only move labels. Of course, after 1 year, when I will see my code I will be like "What? I see Qt::CopyAction, but I only move labels, so why I don't use Qt::MoveAction?". But using Qt::CopyAction in this example is correct on QT site?

                jsulmJ 1 Reply Last reply
                0
                • Q qwe3

                  @jsulm I know I have many questions, but I would like to really understand this drag and drop. So most important for me question:
                  for example I have to create simple project when I have big widget and many labels on it. If I drag and drop any label I have to change only it position ( no copy ). So when I started with 10 labels, at the end of app run I will have still 10 labels. So I can use:

                  if ((drag->exec(Qt::CopyAction, Qt::CopyAction ) == Qt::CopyAction )
                  {
                      // moveThatLabel
                  }
                  

                  So I will use only Qt::CopyAction value in application, where I only move labels. Of course, after 1 year, when I will see my code I will be like "What? I see Qt::CopyAction, but I only move labels, so why I don't use Qt::MoveAction?". But using Qt::CopyAction in this example is correct on QT site?

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @qwe3 said in What enum Qt::DropAction really do?:

                  I see Qt::CopyAction, but I only move labels, so why I don't use Qt::MoveAction?"

                  Well, what you do in that if() {} block is up to you. If you move instead of copying then it is your issue, Qt has no control over your code.
                  "But using Qt::CopyAction in this example is correct on QT site?" - sure, why not? Qt does not know what you are doing after exec().

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • Q Offline
                    Q Offline
                    qwe3
                    wrote on last edited by qwe3
                    #11

                    @jsulm Yes and no. I check all possibilites and when I did:

                        auto dragReturnedValue = drag->exec(Qt::ActionMask, Qt::ActionMask);
                        qInfo()<<dragReturnedValue;
                        if (dragReturnedValue == Qt::ActionMask) {
                            child->show();
                            child->setPixmap(pixmap);
                        }
                    

                    The dragReturnedValue is not equal Qt::ActionMask. It is equal Qt::LinkAction, so "Qt::ActionMask" is not only "word". ( In my code I don't use event->setDropAction(Qt::LinkAction) ) I see difference in using Qt::ActionMask and Qt::CopyAction in defaultDropAction.

                    The same with:

                    dragReturnedValue = drag->exec(Qt::IgnoreAction, Qt::IgnoreAction)
                    

                    Here I can't drop labels ( in my code I don't use event->setDropAction(Qt::IgnoreAction) )

                    EDIT: And there are other small icons when I started drag ( right arrow, plus, etc. )

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

                      Hi,

                      ActionMask as it names suggests is to be used as mask with for example Qt::TargetMoveAction to just check whether it's a move action and you'll do something else later on if it's a standard or target move action.

                      The famous third parameter shall be one of the value you pass as possible action.

                      It does not make sense to make the default action link if you only support move and copy.

                      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
                      2

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved