'Adding a Image Button Class

I have a PyQT layout built with QWidget. I have a few labels, buttons, etc and now I want to add a image that changes color on click. For this, I have built a class as opposed to using a default widget. For the default widgets I am easily able to add them back into the main window but I am not sure how to do this with the custom class.

This is how my code is laid out:

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowTitle("Project Starfish Prototype GUI")
        MainWindow.resize(1920, 1080)
        MainWindow.setStyleSheet("background-color: rgb(9, 40, 122);")

        self.cameraViewer = QtWidgets.QWidget(MainWindow)
        self.cameraViewer.setObjectName("cameraViewer")

        self.logo =  QtWidgets.QLabel(self.cameraViewer)
        self.logo.setGeometry(QtCore.QRect(825, 20, 270, 42))
        pixmap = QPixmap('teleflex-logo.png')
        pixmap = pixmap.scaled(270, 42)        
        self.logo.setPixmap(pixmap)

        self.cameraFeed = QtWidgets.QLabel(self.cameraViewer)
        self.cameraFeed.setGeometry(QtCore.QRect(320, 110, 1280, 960))
        self.cameraFeed.setObjectName("cameraFeed")

        self.startBTN = QtWidgets.QPushButton(self.cameraViewer)
        self.startBTN.setGeometry(QtCore.QRect(110, 610, 100, 100))
        self.startBTN.setObjectName("startBTN")
        self.startBTN.clicked.connect(self.StartFeed)

There is some more code but this is the jist. I add the default QButton or QLabel to the main QWidget.

Now I am trying to add my Class to the main window but I am not sure how to do this.

Here is my code for adding the Class (inside setupUI) to the main window and then my class:

        self.imageButton =  PicButton(QPixmap("image.png"))
        self.imageButton = self.imageButton(self.cameraViewer)
        self.imageButton.setGeometry(QtCore.QRect(110, 110, 100, 100))
        self.imageButton.setObjectName("imageButton")
class PicButton(QAbstractButton):
    def __init__(self, pixmap, parent=None):
        super(PicButton, self).__init__(parent)
        self.pixmap = pixmap
    
    def hover(self):

    def click(self):

I do understand that my code does not make sense, specifically this line self.imageButton = self.imageButton(self.cameraViewer) but I am not sure what the solution is.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source