K
K
KGserega2020-11-05 15:03:38
PyQt
KGserega, 2020-11-05 15:03:38

Is it possible to programmatically find a PyQt5 widget in Python3, by name (string value)?

I'm quite new to Python. By email books I can't figure out from the ones I have. Or advise how to do it or advise the primer.
The program creates Label groups. At the development stage, it is not known how many there may be.
In a separate class, override Label - clicked = QtCore.pyqtSignal()
In the class that creates "Label groups"

map_ = QtCore.QSignalMapper(self)    # Создаем маппер
self.labelTools.clicked.connect(map_.map)    # Привязываем
map_.setMapping(self.labelTools, int(self.numWin))    # Передаем индекс

#В слоте   -                    
@QtCore.pyqtSlot(int)
def on_click(self, index):
    print(str(index))
    w = QWidget.sender(self)
    print(w.sender().objectName())    # пишет имя Label  
    wp = w.sender().parent()
    print(wp.objectName())    # имя родителя

In the slot, we get the name of the Label and its parent. At a minimum, you need to have access to self. toolButton .setGeometry. But full access to the widget is better, the name of which is displayed in the console by the script.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question