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. How to detect the drop target?
Forum Updated to NodeBB v4.3 + New Features

How to detect the drop target?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.9k 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.
  • K Offline
    K Offline
    KrishnaPG
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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
      0
      • K Offline
        K Offline
        KrishnaPG
        wrote on last edited by
        #3

        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
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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
          0

          • Login

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