Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find an object by name in pyqt?

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()

like image 450
MaxKu Avatar asked Sep 27 '13 10:09

MaxKu


People also ask

How to get the object name of spin box in PyQt5?

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.

How to get the child of a checkbox in PyQt?

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 in Qt?

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 .

What are the widgets used in our PyQt5 programme?

In Our PyQt5 Programme, we use Qline Edits, QcheckBox, QListwidget several times. What are the widgets used in Our Programme with Widget names ?


1 Answers

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.

like image 197
Pavel Strakhov Avatar answered Sep 16 '22 20:09

Pavel Strakhov