0

I have this following code snippet to evaluate rowsMoved. I have used the QT editor and don't want to have to subclass (as other examples seem to want to show) and do are replaceWidget for every list widget in the program

So i stumbled upon rowsMoved though @vince in PySide: Drag and drop files into QListWidget

self.win.list_SocketGroups.model().rowsMoved.connect(self.my_method)

@Slot()
def my_method(self, parent, start, end, destination, row):
    print("my_method, rows moved parent", type(parent), parent)
    print("my_method, rows moved start", type(start), start)
    print("my_method, rows moved end", type(end), end)
    print("my_method, rows moved destination", type(destination), destination)
    print("my_method, rows moved row", type(row), row)
    print()

the output is :

<PySide6.QtWidgets.QLineEdit(0x26890824100, name="lineedit_SkillLabel") at 0x00000268913140C0>
my_method, rows moved parent <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689998AEC0>
my_method, rows moved start <class 'int'> 0
my_method, rows moved end <class 'int'> 0
my_method, rows moved destination <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689600D8C0>
my_method, rows moved row <class 'int'> 2

<PySide6.QtWidgets.QLineEdit(0x26890824100, name="lineedit_SkillLabel") at 0x00000268913140C0>
my_method, rows moved parent <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689998AEC0>
my_method, rows moved start <class 'int'> 0
my_method, rows moved end <class 'int'> 0
my_method, rows moved destination <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689600D8C0>
my_method, rows moved row <class 'int'> 2

<PySide6.QtWidgets.QLineEdit(0x26890824100, name="lineedit_SkillLabel") at 0x00000268913140C0>
my_method, rows moved parent <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689998AEC0>
my_method, rows moved start <class 'int'> 0
my_method, rows moved end <class 'int'> 0
my_method, rows moved destination <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689600D8C0>
my_method, rows moved row <class 'int'> 2

<PySide6.QtWidgets.QLineEdit(0x26890824100, name="lineedit_SkillLabel") at 0x00000268913140C0>
my_method, rows moved parent <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689998AEC0>
my_method, rows moved start <class 'int'> 0
my_method, rows moved end <class 'int'> 0
my_method, rows moved destination <class 'PySide6.QtCore.QModelIndex'> <PySide6.QtCore.QModelIndex(-1,-1,0x0,QObject(0x0)) at 0x000002689600D8C0>
my_method, rows moved row <class 'int'> 2

As can be seen, it is called four times, with the same information.

The Question: Was there something I was to do to acknowledge the call, like an event has event.accept and ignore, to stop the call coming through four times ?

Thanks

  • I don't understand. What do you want to achieve? Is the issue the fact that the slot is called four times? Please explain the exact actions you did, and provide a [mre]. Also consider that, while it's not impossible to have control over events without subclassing, it's normally done under specific circumstances and *as long as it makes sense*. Drag&drop is normally quite complex, and using event filtering (or even monkey patching) results in making things much more convoluted and risky. The reality is, subclassing is an essential aspect of Qt (most of its classes are, in fact, subclasses). – musicamante Sep 23 '22 at 14:48
  • I think the info is pretty good. and the question is solid. Yes the problem is it's being called four times. As to what triggered it, well i moved a row in the widget. –  Sep 23 '22 at 22:10
  • Expanded the question slightly to highlight the four times being an issue –  Sep 23 '22 at 22:17
  • Sorry, but no: the information is still insufficient, as you didn't provide an actual MRE *nor* explained what *specific* action are you doing that results in that output. Besides, this phrase is quite unclear: "do are replaceWidget for every list widget in the program"; why would you replace the list widgets? If you believe that using subclasses would require to replace widgets created in Designer, then you're wrong: use promoted widgets. – musicamante Sep 23 '22 at 22:35
  • by "use promoted widgets" do you mean ? –  Sep 24 '22 at 02:46
  • I've not read that carefully enough, but, yes, that's the concept. Just create your subclass, then in Designer promote those QListWidgets for which you want a custom behavior implemented in python. As said, subclassing is quite standard procedure (not only in Qt, even in Python), so, just do it and don't try to find awkward workarounds. Note: as mentioned, drag&drop is not immediate; please take your time to carefully read the documentation and look for examples/tutorials, and remember that the default behavior uses *serialization* of objects. – musicamante Sep 24 '22 at 03:24

0 Answers0