QListWidget drag and drop does not work
-
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:
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)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
-
Hi,
Which version of PyQt5 ?
On which Windows version ?Please provide a minimal runnable example that shows the behaviour your seeing.
-
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 -
Hence my suggestion of providing a minimal runnable example. Writing it may help you find the actual issue you are having.
-
Here is a minimal version, the problem seems to come from the realsense library, without its, DAD works
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_()) -
Glad you found a solution and thanks for sharing !
Can you explain a bit more about it ?