How to find an object by name in pyqt?
To find all the QCheckBox items in your UI you can run a loop through all the children of the widget like as below:
from PyQt5.QtWidgets import QCheckBox
from PyQt5.QtCore import QObject
class Mainwindow(QMainWindow):
def __init__(self):
# super().__init__()
self.checkbox = QCheckBox(self)
self.checkbox_1 = QCheckBox(self)
for checkstate in self.findChildren(QCheckBox):
print(f'get check state:{checkstate.checkState()}')
You can use QObject::findChild
method. In pyqt it should be written like this:
checkbox = self.findChild(QtGui.QCheckBox, "checkBoxEnabled")
self
should be a parent widget of the checkbox.