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

Drag from a QListWidget causing crash

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 721 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.
  • N Offline
    N Offline
    Niagarer
    wrote on 14 Jan 2020, 16:36 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Jan 2020, 19:33 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

      N 1 Reply Last reply 14 Jan 2020, 19:55
      0
      • S SGaist
        14 Jan 2020, 19:33

        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 ?

        N Offline
        N Offline
        Niagarer
        wrote on 14 Jan 2020, 19:55 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 14 Jan 2020, 22:41 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

          N 1 Reply Last reply 15 Jan 2020, 13:34
          2
          • S SGaist
            14 Jan 2020, 22:41

            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.

            N Offline
            N Offline
            Niagarer
            wrote on 15 Jan 2020, 13:34 last edited by
            #5

            @SGaist Oh, really! Ok...
            Bugreport

            1 Reply Last reply
            3
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 15 Jan 2020, 14:18 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

              2/6

              14 Jan 2020, 19:33

              topic:navigator.unread, 4
              • Login

              • Login or register to search.
              2 out of 6
              • First post
                2/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved