Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [SOLVED, moved] Drag from another application and drop to a PySide app?
QtWS25 Last Chance

[SOLVED, moved] Drag from another application and drop to a PySide app?

Scheduled Pinned Locked Moved Language Bindings
3 Posts 2 Posters 5.4k 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.
  • T Offline
    T Offline
    ThomasDalla
    wrote on last edited by
    #1

    Dear community,

    I am trying to implement a dropEvent in a PySide application to open a file when someone drags it from the file explorer and drops it in the PySide application.

    So I added self.setAcceptDrops(True) in the init of my MainWindow and implemented a dropEvent like that:

    @
    def init(self):
    ...
    self.setAcceptDrops(True)
    def dropEvent(self, *args, **kwargs):
    print args@

    However, I cannot drop to my application.
    The cursor is a ∅ that doesn't want me to drop there...

    How can I drop something in a PySide application?

    Note: I tried adding setAcceptDrops(True) to inside widgets, it doesn't work neither.

    1 Reply Last reply
    0
    • frankcyblogic.deF Offline
      frankcyblogic.deF Offline
      frankcyblogic.de
      wrote on last edited by
      #2

      You also have to implement the "dragEnterEvent()":http://doc.qt.nokia.com/4.7/qwidget.html#dragEnterEvent to tell the window system which drags you actually want to accept.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThomasDalla
        wrote on last edited by
        #3

        Oh yeah I didn't notice I have to "accept" the drag first, thanks ;)

        If it helps anyone who was also wondering how to do a drag an drop in PySide, here is my working code:
        @ @Slot(QDropEvent)
        def dropEvent(self, event):
        self.loadInputFile(self.dropFile)
        @Slot(QDragEnterEvent)
        def dragEnterEvent(self, event):
        m = event.mimeData()
        if m.hasUrls():
        self.dropFile = m.urls()[0].toLocalFile()
        event.acceptProposedAction()@

        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