KusGrus
KusGrus

Reputation: 85

PyQt children widgets

I have vertical layout (payment_dateLayout) and some line edit inside. Is there a way to get around all the line edits in the loop and get their name?

self.payment_dateLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_7)

enter image description here

Upvotes: 2

Views: 1282

Answers (1)

Christian Karcher
Christian Karcher

Reputation: 3631

I am a bit confused as to why there seem to be two nested vertical layouts (self.verticalLayoutWidget_7 is placed inside QtWidgets.QVBoxLayout()), so I'll just assume that self.verticalLayoutWidget_7 is the one containing the line edits.

You can loop through the elements of a layout by using its itemAt method and iterating over the number of children (count()):

names = []
for i_widget in range(self.verticalLayoutWidget_7.count()):
    child = self.verticalLayoutWidget_7.itemAt(i_widget).widget()
    names.append(child.objectName())
print(names)

Upvotes: 2

Related Questions