Drag and drop from PySide2 QSqlTableModel (or any Qt model/view) into another windows application

24 views
Skip to first unread message

Benjam901

unread,
Jan 14, 2021, 5:16:42 PMJan 14
to Python Programming for Autodesk Maya
Hello all,

I am starting a dedicated thread for this in case it gets solved and someone comes along and finds the solution.

I have an application that sets up a QSqlTableModel with filepaths and names etc. On Mac OS dragging from QSqlTableModel by simply overriding mimeData() works a treat but windows is another story.

I have tried the following for windows with no luck:

mime_data = QMimeData()
mime_data.setUrls(files[0])
mime_data.setText(files[0])

b = bytearray()
b.extend(map(ord, files[0]))
mime_data.setData('text/plain', QByteArray(b))


Gist of my basic sqltablemodel:

Has anyone ever gotten tis behaviour to work before? I googled around and someone 12 years ago solved it using pywincom (or so they claim) but I cannot get his example to work, it just kills my app wholesale:


any help would be much appreciated on this!

// Ben

Benjam901

unread,
Jan 15, 2021, 3:38:33 AMJan 15
to Python Programming for Autodesk Maya
From Justin:

Well if you are now setting both url and text mime types, and the target is still rejecting the drop, the only other thing I can think of is that it is looking at the drop action (copy vs move vs targetmove) and still rejected it.

If you create your own qt window app to accept the drop and print the mime, does it work? Is it even your own qt target windows that dont work, or just some other windows apps?

Benjam901

unread,
Jan 25, 2021, 1:29:45 PMJan 25
to Python Programming for Autodesk Maya
Ok, I got it. If you have been wandering around the net looking for the answer in how to set up your mime data so that windows applications accept it from your Qt app here is how I got it working.

Windows requires the filepath to be prepended file:/// and by using QUrl.fromLocalFile() we can get this easily.

def mimeData(self, files):
    data = QMimeData()
    urls = list()
    for f in files:
        urls.append(QUrl.fromLocalFile(f))
data.setUrls(urls)
return data


// Ben


Reply all
Reply to author
Forward
0 new messages