I have a list of dictionaries:
globalParams = [{'attr':'enabled','ctrl':'checkBoxEnabled','type':'checkBox'},
{'attr':'colorMode','ctrl':'comboBoxColorMode','type':'comboBox'}]
'ctrl' - name of the control in the Qt window.
typically, the code is as follows:
self.checkBoxEnabled.checkState()
but checkBoxEnabled is an object. and i have only a string name 'checkBoxEnabled' and cannot use it...
how to find an object by name in pyqt? something like? self.GetObjectByName('checkBoxEnabled').checkState()
In this article we will see how we can access the object name of the spin box, object name is basically name given to the object of spin box, when we find the object in the PyQt5 application with the help of object name with the help of findChild method. Object name can be set to the spin box with the help of setObjectName method.
You can use QObject::findChild method. In pyqt it should be written like this: self should be a parent widget of the checkbox. Show activity on this post. Thanks for contributing an answer to Stack Overflow!
How to Access Named Objects The easiest situation is where an application object has been given an explicit name by the programmer. For example, using the Qt toolkit, an object can be given a name like this: When an object is given a name in this way, we can identify it using a real name that specifies just two properties: type and name .
In Our PyQt5 Programme, we use Qline Edits, QcheckBox, QListwidget several times. What are the widgets used in Our Programme with Widget names ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With