Qt QButtonGroup类的使用,添加多个button
1. 场景
界面里面有多个按钮
每个按钮都需要连接槽函数,就会很麻烦
Qt里有QButtonGroup类,简化代码
2. 代码
1. Qt help
1.1. QButtonGroup 类的介绍
The QButtonGroup class provides a container to organize groups of button widgets
1.2
void QButtonGroup::addButton(QAbstractButton *button, int id = -1)
Adds the given button to the button group. If id is -1, an id will be assigned to the button. Automatically assigned ids are guaranteed to be negative, starting with -2. If you are assigning your own ids, use positive values to avoid conflicts.
如果是你自己给 id 赋值,使用正数,避免冲突
1.3
QList<QPushButton*>l