I'm trying to use QPainter-made object along with native widgets of PyQt in one layout and having a difficulty doing so.
I've tried using addWidget()
to add it to the layout but no luck.
class window(QWidget):
def __init__(self):
super().__init__()
self.resize(600, 500)
self.setWindowTitle('GUI 2.0')
#LCD
self.lcd = QLCDNumber()
self.lcd.setFixedHeight(100)
#Slider
self.slider = QSlider(Qt.Horizontal)
self.slider.setMaximum(40)
self.slider.setMinimum(0)
self.slider.valueChanged.connect(self.progress)
#Push button
pb = QPushButton('Button', self)
pb.clicked.connect(self.button)
#Progress Bar
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)
self.pbar.setTextVisible(False)
#Qpainter
painter = QPainter()
painter.setPen(QPen(Qt.black, 5, Qt.SolidLine))
painter.setBrush(QBrush(Qt.green, Qt.DiagCrossPattern))
painter.drawRect(100, 15, 400,200)
#Grid Layout
layout = QGridLayout()
layout.addWidget(self.lcd, 1, 1)
layout.addWidget(self.slider, 2, 1)
layout.addWidget(pb, 2, 2)
layout.addWidget(self.pbar, 0, 1)
layout.addWidget(painter) # doesn't work!
self.setLayout(layout)
My aim is for something like this where the slider will eventually change the water level in the tank and the button will reset the slider value and therefore empty the tank:
Whereas I have something like this:
How can I add the painter object to the layout?