Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Drag from a QListWidget causing crash
Qt 6.11 is out! See what's new in the release blog

Drag from a QListWidget causing crash

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 1.8k 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.
  • NiagarerN Offline
    NiagarerN Offline
    Niagarer
    wrote on last edited by Niagarer
    #1

    Hi!
    This is surely something trivial, but I just don't get it. Unfortunately, the QtForPython documentation does not really address this (yet).
    I am trying to implement the simplest possible drag and drop system between a QListWidget and a QGraphicsView. Basically, this should just send a string to the QGraphicsView.
    You can just copy the code.

    import sys
    from PySide2.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, 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_())
    

    it works without the mimeData method (but of course, I want to transfer a specific string, not the item itself). With the method, the application just crashes when I try to drag an item without any further useful error message
    Do you know whats wrong with the code above?
    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Would you mind sharing the rest of the script so that people can try reproducing your issue ?

      By the way, are you using PySide2 or PyQt5 ? Which version ? On what OS ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      NiagarerN 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Would you mind sharing the rest of the script so that people can try reproducing your issue ?

        By the way, are you using PySide2 or PyQt5 ? Which version ? On what OS ?

        NiagarerN Offline
        NiagarerN Offline
        Niagarer
        wrote on last edited by Niagarer
        #3

        @SGaist
        Yeah, it's actually just that, I don't drag any items outside, the dragging itself is the problem (so the environment shouldn't matter I guess).
        I just updated the question with a small working code producing the same result.

        Sorry, forgot to point out, I am using PySide2-5.14.0 on Win10

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Well, there's nothing fundamentally wrong that I can see with what you wrote so I think you may have found a bug in PySide2. It also crashes on macOS.

          Please check the bug report system to see if there's already something there. If not, please open a new report providing the code you posted here.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          NiagarerN 1 Reply Last reply
          2
          • SGaistS SGaist

            Well, there's nothing fundamentally wrong that I can see with what you wrote so I think you may have found a bug in PySide2. It also crashes on macOS.

            Please check the bug report system to see if there's already something there. If not, please open a new report providing the code you posted here.

            NiagarerN Offline
            NiagarerN Offline
            Niagarer
            wrote on last edited by
            #5

            @SGaist Oh, really! Ok...
            Bugreport

            1 Reply Last reply
            3
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Thanks !

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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