I've got a problem, that i have stumbled across several times.
I want to create an arbitrary number of QCheckBoxes
on a QPushButton
event.
I defined a function wich will be executed by clicking the PushButton
. It should make some CheckBoxes
, but nothing is shown an the MainWindow
. However if I execute the function while creating the MainWindow
it works perfectly fine.
I've tried to call the .update()
, .repaint()
functions in the called function, but nothing happened. I've also tried the janky .hide()
.show()
fix, but nothing here too.
I think I'm missing out on something big.
I include a Minimal example. For keeping things simple I always add two checkboxes, in my project it would depend on the amount of textfiles in a directory. I commented the function call at creating the MainWindow
wich would work fine.
minimal Code Example
import sys
from PyQt5 import QtCore
from PyQt5 import QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self,*args,**kwargs):
super(MainWindow,self).__init__(*args,**kwargs)
self.c_boxes = []
self.pushButton = QtWidgets.QPushButton( 'HI',self)
self.pushButton.clicked.connect(self.action)
#self.action()
def action(self):
for i in range(2):
c_box=QtWidgets.QCheckBox(self)
c_box.move(10,25+ 25*i)
self.c_boxes.append(c_box)
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()