@@ -137,58 +137,64 @@ MainWindow::MainWindow(QWidget *parent)
137137 // 连接信号和槽
138138
139139 // 禁用状态控制
140- connect (disableCheckbox, &QCheckBox::toggled, this , [=](bool checked) {
141- button1->setDisabled (checked);
142- button2->setDisabled (checked);
143- button3->setDisabled (checked);
144- button4->setDisabled (checked);
145- button5->setDisabled (checked);
146-
147- if (checked) {
148- statusLabel->setText (tr (" All buttons are disabled" ));
149- } else {
150- statusLabel->setText (tr (" All buttons are enabled" ));
151- }
152- });
140+ connect (disableCheckbox,
141+ &QCheckBox::toggled,
142+ this ,
143+ [button1, button2, button3, button4, button5, statusLabel](bool checked) {
144+ button1->setDisabled (checked);
145+ button2->setDisabled (checked);
146+ button3->setDisabled (checked);
147+ button4->setDisabled (checked);
148+ button5->setDisabled (checked);
149+
150+ if (checked) {
151+ statusLabel->setText (tr (" All buttons are disabled" ));
152+ } else {
153+ statusLabel->setText (tr (" All buttons are enabled" ));
154+ }
155+ });
153156
154157 // 重置按钮状态
155- connect (resetButton, &QPushButton::clicked, this , [=]() {
156- button1->setChecked (false );
157- button2->setChecked (false );
158- button3->setChecked (false );
159- button4->setChecked (false );
160- button5->setChecked (false );
161- statusLabel->setText (tr (" All buttons reset to normal state" ));
162- });
158+ connect (resetButton,
159+ &QPushButton::clicked,
160+ this ,
161+ [button1, button2, button3, button4, button5, statusLabel]() {
162+ button1->setChecked (false );
163+ button2->setChecked (false );
164+ button3->setChecked (false );
165+ button4->setChecked (false );
166+ button5->setChecked (false );
167+ statusLabel->setText (tr (" All buttons reset to normal state" ));
168+ });
163169
164170 // 按钮状态变化信号
165- auto updateStatus = [= ](const QString &name, bool checked) {
171+ auto updateStatus = [statusLabel ](const QString &name, bool checked) {
166172 QString state = checked ? tr (" checked" ) : tr (" unchecked" );
167173 statusLabel->setText (tr (" %1 is %2" ).arg (name).arg (state));
168174 };
169175
170- connect (button1, &QPushButton::toggled, this , [= ](bool checked) {
176+ connect (button1, &QPushButton::toggled, this , [updateStatus ](bool checked) {
171177 updateStatus (tr (" Normal PushButton" ), checked);
172178 });
173179
174- connect (button2, &QToolButton::toggled, this , [= ](bool checked) {
180+ connect (button2, &QToolButton::toggled, this , [updateStatus ](bool checked) {
175181 updateStatus (tr (" Tool Button" ), checked);
176182 });
177183
178- connect (button3, &QPushButton::toggled, this , [= ](bool checked) {
184+ connect (button3, &QPushButton::toggled, this , [updateStatus ](bool checked) {
179185 updateStatus (tr (" Icon Button" ), checked);
180186 });
181187
182- connect (button4, &QPushButton::toggled, this , [= ](bool checked) {
188+ connect (button4, &QPushButton::toggled, this , [updateStatus ](bool checked) {
183189 updateStatus (tr (" Radio Style Button 1" ), checked);
184190 });
185191
186- connect (button5, &QPushButton::toggled, this , [= ](bool checked) {
192+ connect (button5, &QPushButton::toggled, this , [updateStatus ](bool checked) {
187193 updateStatus (tr (" Radio Style Button 2" ), checked);
188194 });
189195
190196 // 鼠标进入/离开事件的状态显示
191- auto installHoverHandler = [= ](QWidget *widget, const QString &name) {
197+ auto installHoverHandler = [statusLabel ](QWidget *widget, const QString &name) {
192198 widget->installEventFilter (new HoverEventFilter (widget, name, statusLabel));
193199 };
194200
0 commit comments