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. Change mouse icon on Macwhen performing a Drag Drop

Change mouse icon on Macwhen performing a Drag Drop

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 6 Posters 6.0k Views
  • 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 SGaist
    19 Jan 2016, 23:32

    Hi,

    Are you creating the QDrag object yourself ?

    J Offline
    J Offline
    jpalbertini
    wrote on 22 Jan 2016, 13:56 last edited by
    #5

    @SGaist :
    Yes I do. I did not tried setting a pixmap to it though, i would prefer, if possible, the system icon instead of a custom one...

    V 1 Reply Last reply 22 Jan 2016, 14:19
    0
    • J jpalbertini
      22 Jan 2016, 13:56

      @SGaist :
      Yes I do. I did not tried setting a pixmap to it though, i would prefer, if possible, the system icon instead of a custom one...

      V Offline
      V Offline
      ValentinMichelet
      wrote on 22 Jan 2016, 14:19 last edited by
      #6

      @jpalbertini
      Could you show us your code please? Or better, provide a minimal code to reproduce this behavior.

      J 1 Reply Last reply 27 Jan 2016, 14:59
      0
      • J jpalbertini
        19 Jan 2016, 09:13

        Hi
        I try to reproduce the behavior of the OSX finder: by default it moves files/directories but press ALT while doing it and it will duplicate, showing a white "+" near the mouse cursor...
        My problem is, i can't reproduce this... I always got the plus sign.
        I tried using the "setCursor" method with something like that in the dragMoveEvent:

        if (event->keyboardModifiers() == modifier)
        		setCursor(Qt::DragCopyCursor);
        	else
        		setCursor(Qt::DragMoveCursor);
        

        It does not work, and worst, it does not change when I use the standard Qt::ArrowCursor...

        I then tried changing the drop action. The only way to remove that "+" icon it to set the action to IgnoreAction, which well, does do anything on drop...

        Anymore tried to do something like that ?

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 22 Jan 2016, 15:02 last edited by
        #7

        @jpalbertini said:

        I try to reproduce the behavior of the OSX finder: by default it moves files/directories but press ALT while doing it and it will duplicate, showing a white "+" near the mouse cursor...

        The possible drop actions are defined when creating/starting the QDrag. So may it be that you only set a single drop action there?
        These drop actions can then be chosen by the user by pressing the modifier keys on the keyboard during the drag.
        Additionally the target widget also can force a specific drop target to be set once you drag over it.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • V ValentinMichelet
          22 Jan 2016, 14:19

          @jpalbertini
          Could you show us your code please? Or better, provide a minimal code to reproduce this behavior.

          J Offline
          J Offline
          jpalbertini
          wrote on 27 Jan 2016, 14:59 last edited by
          #8

          @ValentinMichelet
          the drag is done this way

          QDrag * drag = new QDrag(parentWidget());
          drag->start(Qt::CopyAction | Qt::MoveAction);
          

          Then the drop is here in the dragMoveEvent

          if (event->keyboardModifiers() == modifier)
          	event->setDropAction(Qt::MoveAction);
          else
          	event->setDropAction(Qt::IgnoreAction);
          

          Nothing else is tempering with the event...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 27 Jan 2016, 21:21 last edited by
            #9

            Can you share the complete implementation ?

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

            J 1 Reply Last reply 28 Jan 2016, 08:40
            0
            • S SGaist
              27 Jan 2016, 21:21

              Can you share the complete implementation ?

              J Offline
              J Offline
              jpalbertini
              wrote on 28 Jan 2016, 08:40 last edited by
              #10

              @SGaist
              not all but here is most of it:

              Here ifs the code where we start the D&D operation:

              void QButtonSceneEditor::mouseMoveEvent(QMouseEvent* event)
              {
              	m_bIsMousePressProcessed = false;
              	if(isChecked())
              	{
              		if(!visibleRegion().contains(event->localPos().toPoint()) &&
              			event->buttons().testFlag(Qt::LeftButton))
              		{
              			dragDropManager()->addSceneButton(this);
              
              			QMimeData * mimeData = new QMimeData();
              			mimeData->setData(DVC_SCENE_MIME_DATA, 0);
              			QDrag * drag = new QDrag(parentWidget());
              			drag->setMimeData(mimeData);
              			drag->start(Qt::CopyAction | Qt::MoveAction);
              		}
              	}
              }
              

              It's an custom button we want to move internally into its parent

              void QSceneGroupEditor::dragMoveEvent(QDragMoveEvent * event)
              {
              	if (!event->mimeData()->hasFormat(DVC_SCENE_MIME_DATA))
              	{
              		event->ignore();
              		return;
              	}
              
              	QButtonScene* pScene = sceneAt(event->pos().x(), event->pos().y());
              	if (pScene)
              	{
              		bool bInTop = event->pos().y() <= pScene->geometry().center().y();
              		int iHover = m_lSceneButtons.indexOf(pScene);
              		for (int iDragged(0); iDragged < dragDropManager()->sceneButtonCount(); iDragged++)
              		{
              			QButtonScene* pButton = dragDropManager()->sceneButtonAt(iDragged);
              			if (pButton)
              			{
              				int iButton = m_lSceneButtons.indexOf(pButton);
              				if (m_lSceneButtons.contains(pButton))
              				{
              					if (iHover == iButton || (bInTop && iHover == iButton + 1) || (!bInTop && iHover == iButton - 1))
              					{
              						m_pLblSeparator->hide();
              						return;
              					}
              
              					m_pLblSeparator->show();
              					if (bInTop)
              						m_pLblSeparator->move(pScene->pos().x() - 8, pScene->pos().y() - 8);
              					else
              						m_pLblSeparator->move(pScene->pos().x() - 8, pScene->pos().y() + pScene->geometry().height() - 3);
              				}
              				else
              				{
              					m_pLblSeparator->show();
              					if (bInTop)
              						m_pLblSeparator->move(pScene->pos().x() - 8, pScene->pos().y() - 8);
              					else
              						m_pLblSeparator->move(pScene->pos().x() - 8, pScene->pos().y() + pScene->geometry().height() - 3);
              				}
              			}
              		}
              	}
              	else
              		m_pLblSeparator->hide();
              
              	Qt::KeyboardModifiers modifier = Qt::AltModifier;
              #if defined (Q_OS_MACX)
              	if (event->keyboardModifiers() == modifier)
              		event->setDropAction(Qt::MoveAction);
              	else
              		//event->setDropAction(Qt::IgnoreAction); // Works but, nothing happends...
              		event->setDropAction(Qt::CopyAction);
              #endif
              	m_pButAdd->setVisible(event->keyboardModifiers() == modifier);
              	event->accept();
              }
              

              Unless there is something I did not understand about the D&D and/or the mouse icon management, i can't change the mouse icon unless using the Qt::IgnoreAction...

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jpalbertini
                wrote on 9 Feb 2016, 08:17 last edited by
                #11

                Hum, nobody ?
                Maybe I should report a bug...

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 9 Feb 2016, 21:01 last edited by
                  #12

                  Are you calling acceptProposedAction where appropriate ?

                  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
                  • D Offline
                    D Offline
                    ddze
                    wrote on 9 Feb 2016, 23:43 last edited by
                    #13

                    I believe that is OS specific.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      joorge87
                      wrote on 30 Mar 2017, 10:41 last edited by
                      #14

                      Hi,

                      I have the same problem, did you find a way to solve it?

                      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