I would like to get the list of all QPushButton
in my MainWindow. Actually, I have a QRadioButton
, and when I uncheck it, I would like to disable all the QPushButton
of my window.
How can I do that ?
I would like to get the list of all QPushButton
in my MainWindow. Actually, I have a QRadioButton
, and when I uncheck it, I would like to disable all the QPushButton
of my window.
How can I do that ?
Here is a minimal example:
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QDebug>
int main( int argn, char **argc)
{
QApplication app(argn, argc);
// Creating some content
QWidget window;
QPushButton ba(&window); ba.setObjectName("but1");
QPushButton bb(&window);bb.setObjectName("but2");
QLabel l(&window); l.setObjectName("label");
QPushButton bc(&l);bc.setObjectName("but3");
// Getting all buttons
QList<QPushButton *> butts = window.findChildren<QPushButton *>();
qDebug() << butts.size();
for (const auto *but: butts) qDebug() << " " << but->objectName();
return 0;
}
© 2022 - 2024 — McMap. All rights reserved.