Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to detect the drop target?

    General and Desktop
    2
    4
    3609
    Loading More Posts
    • 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.
    • K
      KrishnaPG last edited by

      Hello, I have implemented my own QMimeData class and overriding the drag drop methods for QTreeWidget (in my custom QTreeWidget derived class).

      Drag & Drop works fine - but I want to customize the DropEvent() functionality based on who is the target (if its my widget or some other widget).

      I am getting called retrieveData(), but from that I cannot tell who is calling it (it could be some other application). And I do not get dropEvent() calls (since the drop is not my control). I have no access to Drag object (since I am not the one starting the Drag drop operation).

      How to customize my drop operation in these situations based on who is asking me the drop data?????

      1 Reply Last reply Reply Quote 0
      • G
        goetz last edited by

        The clean approach would be to implement the distinction in your widgets - they should know what to do with what kind of data. QMimeData should be used as a transport container only, the actual processing is up to the widgets.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • K
          KrishnaPG last edited by

          Thank you - but the drop targets could be outside my application too. For example, notepad etc...

          When my data is dropped onto notepad (lets say), I get the retrieveData() - but that's all. I do not get the dropEvent() or dropMimeData() etc... where I can check the event position.

          Now, the problem is, for the external targets, I need to have a different dropAction behavior rather than the default one - if I can detect the target, then I can modify the dropAction. But since I am not originating the drag, I cannot subscribe to target change notifications.

          Is there anyway to reliably detect the drop target - atleast to the extent that I should be able to kinow that its not same as my widget and do something about the data source?

          1 Reply Last reply Reply Quote 0
          • G
            goetz last edited by

            In the widget that prepares the drag data, you create a [[Doc:QDrag]] object. You eventually call "exec()":/doc/qt-4.8/qdrag.html#exec-2 on that drag. This method has an overload that takes a second parameter, the default action. Set that to be appropriate for the external targets, your internal widgets always can ignore that.

            You might need to reimplement "QAbstractItemView::startDrag() ":/doc/qt-4.8/qabstractitemview.html#startDrag in order to manipulate the drag object.

            I didn't test that recently, but that would be the way I would try first.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply Reply Quote 0
            • First post
              Last post