I'm pretty new in studying Qt and in the case Qt for Python; I've a trouble about the PyQt5 checkbox object. In the following code, as I check a checkbox, I get a signal redirected to the connected function. It rightly shows up if the box has been checked or uncheked, however it seems my script makes confusion among which box has got changed state. For example if I check the first one, then all the checks i perform, after the first one, show the name value bound to the earliest object, like if they all were actually the same object or they have the same address. Instead if I check and uncheck a box, then the next checked one returns the right name bound to that specific checkbox in output. What am I doing wrong?
Here's the class code:
class window_gui(QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
mainWindow = loadUi("utilities/mygui_gui.ui", self)
self.setWindowTitle("window name")
#checkBox per selezione uno: sensore sul checked yes or not
mainWindow.checkOne.clicked.connect(self.selectBooks)
# checkBox per selezione due: sensore sul checked yes or not
mainWindow.checkTwo.toggled.connect(self.selectBooks)
# checkBox per selezione tre: sensore sul checked yes or not
mainWindow.checkThree.toggled.connect(self.selectBooks)
# checkBox per selezione quattro: sensore sul checked yes or not
mainWindow.checkFour.toggled.connect(self.selectBooks)
# checkBox per selezione cinque: sensore sul checked yes or not
mainWindow.checkFive.toggled.connect(self.selectBooks)
def selectBooks(self, toggle):
if toggle == QtCore.Qt.Checked:
if self.checkOne.isChecked():
print(self.checkOne.text(), "1")
elif self.checkTwo.isChecked():
print(self.checkTwo.text(), "2")
elif self.checkThree.isChecked():
print(self.checkThree.text(), "3")
elif self.checkFour.isChecked():
print(self.checkFour.text(), "4")
elif self.checkFive.isChecked():
print(self.checkFive.text(), "5")
else:
print("error")
print('Checked')
else:
print('Unchecked')