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

Dragging an item from a custom QListView causes crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.14.0
    • PySide
    • None
    • I'm on Windows 10, someone experienced the same on macOS.
    • macOS, Windows
    • fa17f867c2dd33aadefa6fe95f80831a83a64a10 (pyside/pyside-setup/5.14)

    Description

      Trying to create a little custom QListView for dragging by implementing mimeTypes and mimeData as follows causes the application to crash.

      MRP:

      import sys
      from PySide2.QtWidgets import QApplication, QMainWindow, QListWidget, QListWidgetItem, QAbstractItemView
      from PySide2.QtCore import QMimeData, QByteArray
      
      class ClassesListWidget(QListWidget):
          def __init__(self):
              super(ClassesListWidget, self).__init__()
      
              self.addItem(QListWidgetItem('first'))
              self.addItem(QListWidgetItem('second'))
      
              self.setSelectionMode(QAbstractItemView.SingleSelection)
              self.setDragEnabled(True)
              self.viewport().setAcceptDrops(True)
              self.setDropIndicatorShown(True)
      
      
          def mimeTypes(self):
              return ['text/plain']
      
          def mimeData(self, items):
              mime_data = QMimeData()
              data = QByteArray(bytes('testdata', 'utf-8'))
              mime_data.setData('text/plain', data)
              return mime_data
      
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super(MainWindow, self).__init__()
              self.setCentralWidget(ClassesListWidget())
      
      
      if __name__ == '__main__':
          app = QApplication(sys.argv)
      
          mw = MainWindow()
          mw.show()
      
          sys.exit(app.exec_())
      

      From here (QtForum)

      Attachments

        1. pyside1189.py
          1 kB
          Friedemann Kleint

        Issue Links

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

          Activity

            People

              kleint Friedemann Kleint
              niagarer Leon Thomm
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes