I am looking for most proper solution for creating composite widgets that I would be able to reuse in few places across application (graphical control interface with several submenus where some complex widgets would be reused).
Mainly I was trying to create custom QWidget, QLabel and QFrame objects that I would be using in several places. I have prepared such example:
class FansLabelsRight(QWidget):
def __init__(self, parent):
super().__init__(parent)
print('is it working?')
self.setGeometry(275,65,110,140)
self.setStyleSheet("background: rgba(255,0,0,50)")
#self.layout = QLayout(self)
self.pane1 = QLabel(self)
self.pane2 = QLabel(self)
self.pane3 = QLabel(self)
pixmap1 = QPixmap('rtC.png')
pixmap2 = QPixmap('rtB.png')
pixmap3 = QPixmap('rtA.png')
self.pane1.setPixmap(pixmap1)
self.pane2.setPixmap(pixmap2)
self.pane3.setPixmap(pixmap3)
#self.layout.addWidget(self.pane1)
#self.layout.addWidget(self.pane2)
#self.layout.addWidget(self.pane3)
self.pane1.setGeometry(30,10,pixmap1.width(), pixmap1.height())
self.pane2.setGeometry(35,30,pixmap2.width(), pixmap2.height())
self.pane3.setGeometry(40,30,pixmap3.width(), pixmap3.height())
self.setLayout(self.layout)
self.show()
It did not worked. As well as few other approach that I tested without positive results expect one that I build based on Q tDesigner - creating custom object which actually add to my QMainWindow class other widgets but it is not what I expected and what I read that should be possible. Other words I think of having container with subwidgets. Is it actually possible?
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
self.label = QLabel(Form)
self.label.setGeometry(QtCore.QRect(60, 10, 61, 81))
self.label.setPixmap(QPixmap("rtA.png"))
self.label.setObjectName("label")
self.label_2 = QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(70, 30, 51, 111))
self.label_2.setPixmap(QPixmap("rtB.png"))
self.label_2.setObjectName("label_2")
self.label_3 = QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(60, 90, 47, 61))
self.label_3.setPixmap(QPixmap("rtC.png"))
self.label_3.setObjectName("label_3")
self.pushButton = QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(0, 0, 75, 61))
self.pushButton.setFlat(True)
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(0, 100, 75, 61))
self.pushButton_2.setFlat(True)
self.pushButton_2.setObjectName("pushButton_2")
QtCore.QMetaObject.connectSlotsByName(Form)
Could you please suggest me how to achieve that? How to create own widget that would be build from several object and will keep whole logic between them inside its class? (As logic I understand that pressing one button will show another label and other button will decrees, etc...)
One of problem that I had was Layouts, which did not let me place these labels where I wanted them.
And here is sample of how should it looks like.