Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-664

mimeData encoding issues



    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Fixed
    • Affects Version/s: 5.6, 5.9
    • Fix Version/s: 5.12.0
    • Component/s: PySide
    • Labels:


      I am trying to drag and drop mimeData in a QTreeView using an QAbstractItemModel (Python 3.6), and I've stumbled upon a few different issues.

      1. I originally wanted to add a Python object to my mimeData stream. But there is no QVariant in PySide2. I can see this being a problem, as I believe there is no good workaround here; you simply cannot "drop" a Python object using drag and drop without QVariant. Am I mistaken?
      2. So I instead wanted to create a dictionary which I wanted to stream (using the "application/json" format). Before adding it as a string to the stream, I need to convert the dictionary to string and UTF8 encode it. I did this with json.dumps(d, ensure_ascii=False).encode('utf-8'). But in the mimeDropData, there's no clear way to decode it. In C++ you would use QString::fromUtf8(). But there's no QString type in PySide2. Unicode is not a thing in Python 3 and str() doesn't work.
      3. QByteArray.data() seems broken; b = QByteArray("hi 猫") , b.data() returns b'hi \xe7' , but it should return b'hi \xe7\x8c\xab'


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            • Assignee:
              crmaurei Cristian Maureira-Fredes
              fredrikaverpil Fredrik Averpil
            • Votes:
              1 Vote for this issue
              4 Start watching this issue


              • Created:

                Gerrit Reviews

                There are no open Gerrit changes