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. QListWidget drag and drop does not work

QListWidget drag and drop does not work

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 2 Posters 1.4k 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.
  • S Offline
    S Offline
    sam37120
    wrote on last edited by
    #1

    I am trying to implement in my project a QListWidget with the possibility of moving elements by drag and drop

    I try to integrate it into the project in the simplest way without success, while outside I have no problem executing it Here is its implementation:

    priorityContainer.py:

    class priorityContainer(QListWidget):
    def __init__(self):
        super().__init__()
        self.setIconSize(QSize(124, 124))
        self.setDragDropMode(QAbstractItemView.InternalMove)
        self.setDefaultDropAction(Qt.MoveAction) 
        self.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.setAcceptDrops(True)
        self.setDragEnabled(True)
    
        for i in range(12):
            QListWidgetItem( 'Item '+str(i), self)
    

    main_interface.py:

    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    from PyQt5.QtCore import *
    import sys, os
    
    from ressource.ResizableWindows import ResizableWindows
    from ressource.Point import paintDot
    from ressource.interface import tab_widget
    from ressource.interface.error import messagederreur
    from ressource.interface import priorityContainer
    
    from ressource.camLabel import camLabel
    from ressource.ToolsBar import toolsBar
    import serveur.xmlrpc_server as xmlrpc_server
    import memoire.XML_manager as XML_manager
    import memoire.modele as modele
    import socket
    
    class UI_main(QMainWindow):
        def __init__(self):
             super(UI_main, self).__init__()
        
             qInstallMessageHandler(messagederreur)
             self.threadpool = QThreadPool()
        
             logo = QPixmap("Ressource/navigation/logo_icon.png")
             self.setWindowIcon(QIcon(logo))
        
             self.server_thread = xmlrpc_server.xmlrpc_server()
             self.server_thread.vid_thread.signals.connection.connect(self.vid_thread_connection)
             self.server_thread.signals.cmdSignal.connect(self.setCmdData)
             self.server_thread.vid_thread.signals.cmdSignal.connect(self.setCmdData)
        
             self.threadpool.start(self.server_thread)
             self.setupUi()
             self.show() 
             [...]
    
        def setupUi(self):
             self.centralwidget = QWidget(self)
             self.mainVcontainer = QVBoxLayout(self.centralwidget)
        
             self.detectionContainer = QWidget()
             self.detectionHContainer = QHBoxLayout(self.detectionContainer)
             self.dataCmdContainer = QVBoxLayout()
             self.dataOrderHContainer = QHBoxLayout()
             [...]
             self.priorityContainer = priorityContainer.priorityContainer()
             self.dataOrderHContainer.addLayout(self.dataVContainer)
             self.dataOrderHContainer.addWidget(self.priorityContainer)
                     
             self.dataCmdContainer.addLayout(self.dataOrderHContainer)   
             [...] 
             self.detectionHContainer.addLayout(self.dataCmdContainer)
        
             [...]
             self.mainVcontainer.addWidget(self.detectionContainer)
             self.setCentralWidget(self.centralwidget)
    

    main.py:

    from ressource.interface.main_interface import UI_main
    from ressource.interface.Tuto import UI_tuto
    import memoire.modele as modele
    [...]

    class Contr```
    oller:
    def init(self):

        modele.init()
        self.parameters = modele.model.globalParameters 
        [...]
    def show_main(self):
        [...]
        self.parameters.save_parameters()
        self.UI_main = UI_main()
        [...]
    [...]
    

    def main():

    app = QApplication(sys.argv)
    controller = Controller()
    
    myappid = 'mycompany.myproduct.subproduct.version'  # arbitrary string
    ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
    
    if controller.parameters.guide_done == 0:
        controller.show_tuto()
        sys.exit(app.exec_())
    else:
        controller.show_main()
        sys.exit(app.exec_())
    
    if __name__ == '__main__':
        main()
    

    I am also having problems with the QFileDialog where I have to use QFileDialog.DontUseNativeDialog to not crash the program

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sam37120
      wrote on last edited by
      #6

      I have solved my problem by adding these lines before any other imports where I import my pyrealsense2 librairies:

      import sys
      sys.coinit_flags = 2
      import pythoncom
      
      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Which version of PyQt5 ?
        On which Windows version ?

        Please provide a minimal runnable example that shows the behaviour your seeing.

        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
        • S Offline
          S Offline
          sam37120
          wrote on last edited by
          #3

          I agree unfortunately the problem is there, if I use QListWidget in an isolate way I have no problem, it's context related. For example by removing the imports of other widgets, (and by commenting a good part of the text), I have no problem, it is enough to put these imports again and the problem returns.

          PyQT 5.13.0
          Windows 10 1909 18363.1082

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

            Hence my suggestion of providing a minimal runnable example. Writing it may help you find the actual issue you are having.

            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
            1
            • S Offline
              S Offline
              sam37120
              wrote on last edited by sam37120
              #5

              Here is a minimal version, the problem seems to come from the realsense library, without its, DAD works

              priorityContainer.py:

              class priorityContainer(QListWidget):
              def __init__(self):
                  super().__init__()
                  self.setIconSize(QSize(124, 124))
                  self.setDragDropMode(QAbstractItemView.InternalMove)
                  self.setDefaultDropAction(Qt.MoveAction) 
                  self.setSelectionMode(QAbstractItemView.ExtendedSelection)
                  self.setAcceptDrops(True)
                  self.setDragEnabled(True)
              
                  for i in range(5):
                      QListWidgetItem( 'Item '+str(i), self)
              

              main_interface.py:

              from PyQt5.QtWidgets import *
              import traceback, sys, os
              import pyrealsense2 as rs
              from ressource.interface import priorityContainer
              
              
              class UI_main(QMainWindow):
                  def __init__(self):
                      super(UI_main, self).__init__()
              
                      self.setupUi()
                      self.show()
              
                  def setupUi(self):
                      self.centralwidget = QWidget(self)
                      self.mainVcontainer = QVBoxLayout(self.centralwidget)
              
                      self.listWidget = priorityContainer.priorityContainer()
              
                      self.mainVcontainer.addWidget(self.listWidget)
                      self.setCentralWidget(self.centralwidget)
              
                  def root_path(self):
                      return os.path.abspath(os.sep)
              
              
              if __name__ == "__main__":
                  app = QApplication(sys.argv)
                  ui = UI_main()
                  sys.exit(app.exec_())
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                sam37120
                wrote on last edited by
                #6

                I have solved my problem by adding these lines before any other imports where I import my pyrealsense2 librairies:

                import sys
                sys.coinit_flags = 2
                import pythoncom
                
                1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Glad you found a solution and thanks for sharing !

                  Can you explain a bit more about it ?

                  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