I've come across a weird bug that's happening on both PySide and PySide2. I'm trying to link together two button classes, and if I create a QPainter in any of the classes, Qt just refuses to load.

No tracebacks or anything are output, it just simply quits the second it loads.

Here's some code that can replicate the error:

from Qt import QtCore, QtGui, QtWidgets

class Btn1(QtWidgets.QPushButton):
    def __init__(self, *args, **kwargs):
        super(Btn1, self).__init__(*args, **kwargs)

class Btn2(QtWidgets.QPushButton):
    def __init__(self, *args, **kwargs):
        super(Btn2, self).__init__(*args, **kwargs)

class Btn(Btn1, Btn2):
    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        super(Btn, self).paintEvent(event)

if __name__ == '__main__':

    class ExampleWindow(QtWidgets.QWidget):
        def __init__(self):
            super(ExampleWindow, self).__init__()

            layout = QtWidgets.QVBoxLayout()

    import sys
    app = QtWidgets.QApplication(sys.argv)
    mainWin = ExampleWindow()

Actual Usage:

I have separate classes that each perform a specific function. One for example deals with double clicks, and another deals with drag and drop. As each of these features don't overlap, I was wanting to keep them all separate, and join them together through inheritance.

0 Answers