[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Overriding slots in mixins in PyQt5
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2018-10-25 16:35:23
Message-ID: 0D569CAE-3B6D-449C-82B4-6022B528B745 () riverbankcomputing ! com
[Download RAW message or body]

On 25 Oct 2018, at 2:31 pm, Julio César Gázquez <julio_lists@mebamutual.com.ar> \
wrote:
> 
> 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.

It's a bug that will be fixed in the next snapshot (which won't be tonight).

Thanks,
Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic