[PyQt] Overriding slots in mixins in PyQt5

Julio César Gázquez julio_lists at mebamutual.com.ar
Thu Oct 25 14:31:11 BST 2018


Hi Phil and everybody.

I'm migrating our largest PyQt4 codebase to PyQt5. The process has been
pretty uneventful until now, when I found this.

I have code with the following structure. Running it in PyQt4 I got the
original, expected behavior, and clicking the button triggers the
overriden slot. However in PyQt5 the base slot is triggered.

--- snip ---

import sys

#from PyQt4.QtCore import pyqtSlot, QMetaObject #from PyQt4.QtGui import
QApplication, QWidget, QPushButton, QMessageBox from PyQt5.QtCore import
pyqtSlot, QMetaObject from PyQt5.QtWidgets import QApplication, QWidget,
QPushButton, QMessageBox class BaseMixin:     @pyqtSlot()     def
on_button_clicked(self):         QMessageBox.information(self, 'Base
Widget', 'Base slot') class OverridenMixin(BaseMixin):     @pyqtSlot()
    def on_button_clicked(self):         QMessageBox.information(self,
'Overriden Widget', 'Overriden slot')     class Widget(QWidget,
OverridenMixin):         def __init__(self, parent=None):        
super().__init__(parent)         self.button = QPushButton("Push me",
self)         self.button.setObjectName("button")        
self.button.show()         QMetaObject.connectSlotsByName(self)
                 class App(QApplication):     def __init__(self, argv):
        super().__init__(argv)         self._widget = Widget()        
self._widget.show() app = App(sys.argv) app.exec_() --- snip ---

It got weirder as if I remove the decorators, the overriden slot is
triggered, (yet I'd like to keep using the decorators in order to avoid
getting triggered twice without dealing with the signal's checked
parameter).

I'm not sure if I'm doing something subtly wrong, or just using a
completely unsupported way of doing things, and therefore utterly wrong.

What should I do to get it working correctly, besides removing the
decorators?

BTW, I'd like to keep the code working in PyQt4 for a while, but I'm
afraid this is twisted enough to put extra constraints.

Thanks in advance.

Julio.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181025/2f172459/attachment.html>


More information about the PyQt mailing list