Qt Loop Over Widget

I create a program with ten QLabel by Qt Nokia. I want to loop over that QLabel widget and change property over that widget. I can use qFindChild and findChildren function to loop over widget.  For example, I have ten QLabel with name label_1, label_2, … , label_10. We can loop over that that widget with code :

But if we want change property all widget by type (example. loop over QLabel, QLineEdit, etc) we can use function findChildren.

When we create GUI program with Qt Designer (*.ui file) we can use qFindChild and findChildren function to loop over widget. If we create GUI program without Qt Designer (create GUI  manually), we can not use qFindChild function to loop over wigdet. We only use findChildren function. If we want to know what name of widget, we can use ObjectName function to get name over widget.

Source :
http://www.qtcentre.org/threads/38305-for-loop-application

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.