QT之让QDialogButtonBox::Ok 变成中文”确定“显示

本文介绍了如何在Qt中对QDialogButtonBox内的标准按钮进行文本的本地化处理,通过设置按钮的文字为中文来实现界面的汉化。具体操作包括包含必要的头文件,设置按钮类型并更改按钮显示的文字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要有头文件 #include <QPushButton>
 
原理就是把bottonbox 中的 每一个按钮 转换成pushbutton类的,在settext 就可以了
 
 
 
QDialogButtonBox *buttonBox;
 

buttonBox->setStandardButtons(QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
 
 

  buttonBox->button(QDialogButtonBox::Ok)->setText("确定");//将buttonbox中的ok 变成汉化
   buttonBox->button(QDialogButtonBox::Cancel)->setText("取消");
   buttonBox->button(QDialogButtonBox::Apply)->setText("应用");
#include "financialwidget.h" #include "ui_financialwidget.h" #include <QVBoxLayout> #include <QHBoxLayout> #include <QChart> #include <QChartView> #include <QLabel> #include <QComboBox> #include <QDate> #include <QDateEdit> #include <QPushButton> #include <QStringList> #include <QTableWidget> #include <QSqlQuery> #include <QHeaderView> #include <QDialog> #include <QFormLayout> #include <QLineEdit> #include <QDialogButtonBox> #include <QSqlError> #include <QPieSeries> #include <QPieSlice> #include <QLineSeries> #include <QDateTimeAxis> #include <QValueAxis> #include <QMessageBox> FinancialWidget::FinancialWidget(QWidget *parent) : QWidget(parent) , ui(new Ui::FinancialWidget) { ui->setupUi(this); setupUI(); populateStudentComboBox(); } FinancialWidget::~FinancialWidget() { delete ui; } void FinancialWidget::setupUI() { QVBoxLayout* mainLayout = new QVBoxLayout(this); QHBoxLayout* topLayout = new QHBoxLayout(); QHBoxLayout* middleLayout = new QHBoxLayout(); chartView = new QChartView(); mainLayout->addLayout(topLayout); mainLayout->addLayout(middleLayout, 60); // 占60%高度 mainLayout->addWidget(chartView, 40); // 占40%高度 // =============== 顶部筛选条件与按钮布局 =============== topLayout->addWidget(new QLabel("学生姓名:", this)); studentComboBox = new QComboBox(this); topLayout->addWidget(studentComboBox); topLayout->addWidget(new QLabel("起始日期:", this)); startDateEdit = new QDateEdit(QDate::currentDate().addMonths(-1)); startDateEdit->setCalendarPopup(true); topLayout->addWidget(startDateEdit); topLayout->addWidget(new QLabel("结束日期:", this)); endDateEdit = new QDateEdit(QDate::currentDate()); endDateEdit->setCalendarPopup(true); topLayout->addWidget(endDateEdit); addButton = new QPushButton("添加"); deleteButton = new QPushButton("删除"); editButton = new QPushButton("修改"); topLayout->addWidget(addButton); topLayout->addWidget(deleteButton); topLayout->addWidget(editButton); topLayout->addStretch(); // =============== 主内容布局 =============== tableWidget = new QTableWidget(); tableWidget->setFixedWidth(550); tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); tableWidget->setAlternatingRowColors(true); QStringList header = QStringList() << "ID" << "学生名字" << "缴费日期" << "金额" << "支付类型" << "备注"; tableWidget->setColumnCount(header.count()); tableWidget->setHorizontalHeaderLabels(header); tableWidget->setColumnHidden(0, true); middleLayout->addWidget(tableWidget); //饼状图 pieChartView = new QChartView(); middleLayout->addWidget(pieChartView); chartView->setRenderHint(QPainter::Antialiasing); chartView->setMinimumHeight(200); // 最小高度保障 // 连接 // 打印所有控件地址,检查是否为 nullptr qDebug() << "addButton:" << addButton; qDebug() << "deleteButton:" << deleteButton; qDebug() << "editButton:" << editButton; qDebug() << "studentComboBox:" << studentComboBox; qDebug() << "startDateEdit:" << startDateEdit; qDebug() << "endDateEdit:" << endDateEdit; connect(addButton, &QPushButton::clicked, this, &FinancialWidget::addRecord); connect(deleteButton, &QPushButton::clicked, this, &FinancialWidget::deleteRecord); connect(editButton, &QPushButton::clicked, this, &FinancialWidget::editRecord); connect(studentComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FinancialWidget::loadFinancialRecords); connect(startDateEdit, &QDateEdit::dateChanged, this, &FinancialWidget::loadFinancialRecords); connect(endDateEdit, &QDateEdit::dateChanged, this, &FinancialWidget::loadFinancialRecords); } void FinancialWidget::loadFinancialRecords() { tableWidget->setRowCount(0); QString studentId = studentComboBox->currentData().toString(); QDate startDate = startDateEdit->date(); QDate endDate = endDateEdit->date(); QString queryStr = QString( "SELECT fr.id, s.name, fr.payment_date, fr.amount, fr.payment_type, fr.notes " "FROM financialRecords fr " "JOIN studentInfo s ON fr.student_id = s.id " "WHERE fr.payment_date BETWEEN '%1' AND '%2' %3" ).arg(startDate.toString("yyyy-MM-dd"), endDate.toString("yyyy-MM-dd"), (studentId != "-1") ? QString("AND fr.student_id = '%1'").arg(studentId) : ""); QSqlQuery query(queryStr); while (query.next()) { int row = tableWidget->rowCount(); tableWidget->insertRow(row); for (int col = 0; col < 6; ++col) { QTableWidgetItem* item = new QTableWidgetItem(query.value(col).toString()); item->setTextAlignment(Qt::AlignCenter); tableWidget->setItem(row, col, item); } } tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); //updateChart(); // 更新下方折线图 updatePieChart(); // 更新右侧饼图 } void FinancialWidget::populateStudentComboBox() { studentComboBox->clear(); studentComboBox->addItem("所有学生", QVariant("-1")); // "-1" 表示所有学生 QSqlQuery query("SELECT id, name FROM studentInfo"); while (query.next()) { QString id = query.value(0).toString(); // id 是字符串类型 QString name = query.value(1).toString(); studentComboBox->addItem(name, QVariant(id)); } } void FinancialWidget::addRecord() { QDialog dialog(this); dialog.setWindowTitle("添加缴费记录"); QFormLayout form(&dialog); // 学生名称下拉菜单 QComboBox* studentNameComboBox = new QComboBox(&dialog); QSqlQuery query("SELECT id, name FROM studentInfo"); while (query.next()) { QString id = query.value(0).toString(); QString name = query.value(1).toString(); studentNameComboBox->addItem(name, QVariant(id)); // 将学生ID与名称关联 } QDateEdit* paymentDateEdit = new QDateEdit(&dialog); paymentDateEdit->setDate(QDate::currentDate()); // 设置默认值为当前日期 paymentDateEdit->setCalendarPopup(true); // 允许弹出日历选择器 QLineEdit* amountEdit = new QLineEdit(&dialog); QLineEdit* feeTypeEdit = new QLineEdit(&dialog); QLineEdit* remarkEdit = new QLineEdit(&dialog); form.addRow("学生名称:", studentNameComboBox); form.addRow("缴费日期:", paymentDateEdit); // 修改为 QDateEdit form.addRow("金额:", amountEdit); form.addRow("支付类型:", feeTypeEdit); form.addRow("备注:", remarkEdit); QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); buttonBox.button(QDialogButtonBox::Ok)->setText("确定"); buttonBox.button(QDialogButtonBox::Cancel)->setText("取消"); form.addRow(&buttonBox); QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); QObject::connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); if (dialog.exec() == QDialog::Accepted) { QString studentId = studentNameComboBox->currentData().toString(); QString paymentDate = paymentDateEdit->date().toString("yyyy-MM-dd"); double amount = amountEdit->text().toDouble(); QString feeType = feeTypeEdit->text(); QString remark = remarkEdit->text(); // 准备SQL查询 QSqlQuery query; query.prepare("INSERT INTO financialRecords (student_id, payment_date, amount, payment_type, notes) " "VALUES (:student_id, :payment_date, :amount, :payment_type, :notes)"); query.bindValue(":student_id", studentId); // 绑定学生ID query.bindValue(":payment_date", paymentDate); query.bindValue(":amount", amount); query.bindValue(":payment_type", feeType); query.bindValue(":notes", remark); // 执行SQL查询 if (query.exec()) { qDebug() << "记录添加成功!"; loadFinancialRecords(); // 刷新表格 } else qDebug() << "添加记录失败:" << query.lastError().text(); } } void FinancialWidget::updatePieChart() { QString studentId = studentComboBox->currentData().toString(); QDate startDate = startDateEdit->date(); QDate endDate = endDateEdit->date(); // 使用预编译防止 SQL 注入 QString baseQuery = QString( "SELECT payment_type, SUM(amount) " "FROM financialRecords " "WHERE payment_date BETWEEN :startDate AND :endDate %1 " "GROUP BY payment_type") .arg(studentId != "-1" ? "AND student_id = :studentId" : ""); QSqlQuery query; query.prepare(baseQuery); query.bindValue(":startDate", startDate.toString("yyyy-MM-dd")); query.bindValue(":endDate", endDate.toString("yyyy-MM-dd")); if (studentId != "-1") { query.bindValue(":studentId", studentId); } if (!query.exec()) { qDebug() << "Query failed:" << query.lastError(); return; } QPieSeries* series = new QPieSeries(); while (query.next()) { QString type = query.value(0).toString(); qreal value = query.value(1).toDouble(); if (value > 0) { QString legendLabel = QString("%1<br>%2元").arg(type).arg(value); QPieSlice* slice = new QPieSlice(legendLabel, value); slice->setLabelVisible(false); series->append(slice); } } QChart* chart = new QChart(); chart->addSeries(series); chart->setTitle("支付类型分布"); // 图例设置 chart->legend()->setVisible(true); chart->legend()->setAlignment(Qt::AlignBottom); chart->legend()->setBackgroundVisible(true); chart->legend()->setBrush(QBrush(Qt::white)); chart->legend()->setLabelColor(Qt::black); chart->legend()->setContentsMargins(10, 10, 10, 10); // 饼图尺寸 series->setPieSize(0.75); if (pieChartView->chart()) { delete pieChartView->chart(); } pieChartView->setChart(chart); // 强制重绘 pieChartView->repaint(); } /* void FinancialWidget::updateChart() { // ================== 1. 获取并验证日期范围 ================== QDate startDate = startDateEdit->date(); QDate endDate = endDateEdit->date(); if (startDate > endDate) { std::swap(startDate, endDate); startDateEdit->setDate(startDate); endDateEdit->setDate(endDate); } // ================== 2. 构建安全SQL查询 ================== QString studentId = studentComboBox->currentData().toString(); // 如果 studentId 为 "-1"(不筛选特定学生),直接返回 if (studentId == "-1") { qDebug() << "未选择特定学生,跳过饼图更新"; return; } QString queryStr = QString("SELECT DATE(payment_date) AS day, SUM(amount) AS total " "FROM financialRecords " "WHERE payment_date BETWEEN :startDate AND :endDate " "%1 GROUP BY day ORDER BY day" ).arg(studentId != "-1" ? "AND student_id = :studentId" : ""); QSqlQuery query; query.prepare(queryStr); query.bindValue(":startDate", startDate.toString("yyyy-MM-dd")); query.bindValue(":endDate", endDate.toString("yyyy-MM-dd")); if (studentId != "-1") query.bindValue(":studentId", studentId); if (!query.exec()) qCritical() << "[SQL错误]" << query.lastError().text(); // ================== 3. 处理查询数据 ================== QMap<QDate, qreal> dayData; qreal maxAmount = 0; while (query.next()) { QDate day = QDate::fromString(query.value(0).toString(), "yyyy-MM-dd"); if (!day.isValid()) continue; qreal amount = query.value(1).toDouble(); dayData[day] = amount; if (amount > maxAmount) maxAmount = amount; } // ================== 4. 创建图表系列 ================== QLineSeries* series = new QLineSeries(); series->setName("销售额"); QPen pen(Qt::blue); series->setPen(pen); QDate currentDate = startDate; while (currentDate <= endDate) { qreal value = dayData.value(currentDate, 0.0); series->append(currentDate.startOfDay().toMSecsSinceEpoch(), value); currentDate = currentDate.addDays(1); } // ================== 5. 配置坐标轴 ================== QChart* chart = new QChart(); chart->addSeries(series); QDateTimeAxis* axisX = new QDateTimeAxis(); axisX->setFormat("yyyy-MM-dd"); axisX->setTitleText("日期"); axisX->setRange(startDate.startOfDay(),endDate.startOfDay()); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); QValueAxis* axisY = new QValueAxis(); axisY->setTitleText("金额 (元)"); axisY->setLabelFormat("%.0f"); chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY); // ================== 6. 应用图表 ================== if (chartView->chart()) delete chartView->chart(); chartView->setChart(chart); chartView->setRenderHint(QPainter::Antialiasing); chart->legend()->setVisible(false); } */ void FinancialWidget::editRecord() { int currentRow = tableWidget->currentRow(); if (currentRow < 0) { QMessageBox::warning(this, "警告", "请选择要修改的记录!"); return; } // 获取当前行的数据 QString id = tableWidget->item(currentRow, 0)->text(); // ID 是字符串类型 QString studentName = tableWidget->item(currentRow, 1)->text(); // 学生名称 QString paymentDate = tableWidget->item(currentRow, 2)->text(); QString amount = tableWidget->item(currentRow, 3)->text(); QString feeType = tableWidget->item(currentRow, 4)->text(); QString remark = tableWidget->item(currentRow, 5)->text(); QDialog dialog(this); dialog.setWindowTitle("修改缴费记录"); QFormLayout form(&dialog); // 学生名称下拉菜单 QComboBox* studentNameComboBox = new QComboBox(&dialog); QSqlQuery query("SELECT id, name FROM studentInfo"); while (query.next()) { QString id = query.value(0).toString(); // id 是字符串类型 QString name = query.value(1).toString(); studentNameComboBox->addItem(name, QVariant(id)); } studentNameComboBox->setCurrentText(studentName); // 设置当前学生名称 QLineEdit* paymentDateEdit = new QLineEdit(paymentDate, &dialog); QLineEdit* amountEdit = new QLineEdit(amount, &dialog); QLineEdit* feeTypeEdit = new QLineEdit(feeType, &dialog); QLineEdit* remarkEdit = new QLineEdit(remark, &dialog); form.addRow("学生名称:", studentNameComboBox); form.addRow("缴费日期:", paymentDateEdit); form.addRow("金额:", amountEdit); form.addRow("支付类型:", feeTypeEdit); form.addRow("备注:", remarkEdit); QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); buttonBox.button(QDialogButtonBox::Ok)->setText("确定"); buttonBox.button(QDialogButtonBox::Cancel)->setText("取消"); form.addRow(&buttonBox); QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); QObject::connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); if (dialog.exec() == QDialog::Accepted) { QString studentId = studentNameComboBox->currentData().toString(); // studentId 是字符串类型 QString paymentDate = paymentDateEdit->text(); double amount = amountEdit->text().toDouble(); QString feeType = feeTypeEdit->text(); QString remark = remarkEdit->text(); // 准备 SQL 查询 QSqlQuery query; query.prepare("UPDATE financialRecords SET student_id = :student_id, payment_date = :payment_date, " "amount = :amount, payment_type = :payment_type, notes = :notes WHERE id = :id"); query.bindValue(":student_id", studentId); // studentId 是字符串类型 query.bindValue(":payment_date", paymentDate); query.bindValue(":amount", amount); query.bindValue(":payment_type", feeType); query.bindValue(":notes", remark); query.bindValue(":id", id); // 执行 SQL 查询 if (query.exec()) { qDebug() << "记录修改成功!"; loadFinancialRecords(); // 刷新表格 } else qDebug() << "修改记录失败:" << query.lastError().text(); } } void FinancialWidget::deleteRecord() { int currentRow = tableWidget->currentRow(); if (currentRow < 0) { QMessageBox::warning(this, "警告", "请选择要删除的记录!"); return; } // 获取 ID 列的值 int id = tableWidget->item(currentRow, 0)->text().toInt(); // ID 列是第一列 // 确认删除操作 QMessageBox confirmBox(this); confirmBox.setWindowTitle("确认删除"); confirmBox.setText("确定要删除该记录吗?"); // 设置按钮为中文 QPushButton* yesButton = confirmBox.addButton("确定", QMessageBox::YesRole); QPushButton* noButton = confirmBox.addButton("取消", QMessageBox::NoRole); // 设置默认按钮 confirmBox.setDefaultButton(noButton); // 显示对话框并等待用户选择 confirmBox.exec(); if (confirmBox.clickedButton() == yesButton) { // 用户点击了“确定” QSqlQuery query; query.prepare("DELETE FROM financialRecords WHERE id = :id"); query.bindValue(":id", id); if (query.exec()) { qDebug() << "记录删除成功!"; loadFinancialRecords(); // 刷新表格 } else { QMessageBox::warning(this, "错误", "删除记录失败!"); } } } #ifndef FINANCIALWIDGET_H #define FINANCIALWIDGET_H #include <QWidget> class QChartView; class QTableWidget; class QComboBox; class QPushButton; class QDateEdit; namespace Ui { class FinancialWidget; } class FinancialWidget : public QWidget { Q_OBJECT public: explicit FinancialWidget(QWidget *parent = nullptr); ~FinancialWidget(); private: void setupUI(); void loadFinancialRecords(); void populateStudentComboBox(); void addRecord(); //void updateChart(); void updatePieChart(); void editRecord(); void deleteRecord(); QChartView* pieChartView; QTableWidget* tableWidget; QComboBox* studentComboBox; QPushButton* addButton; QPushButton* deleteButton; QPushButton* editButton; QChartView* chartView; QDateEdit* startDateEdit; QDateEdit* endDateEdit; Ui::FinancialWidget *ui; }; #endif // FINANCIALWIDGET_H 这是一段完整的financialwidget.h文件和financialwidget.cpp文件在调用void FinancialWidget::updatePieChart()时会导致进程崩溃,我需要你分析并修改
最新发布
06-26
<think>好的,我需要帮助用户理解他们在Qt中遇到的问题。他们提供了三个connect语句,其中前两个是连接accepted和rejected信号到对应的槽函数,第三个连接的是clicked信号。用户的问题是,当使用clicked信号时,不知道具体点击的是哪个按钮,只知道有OK和Cancel按钮。 首先,我应该回顾QDialogButtonBox的相关知识。QDialogButtonBox通常包含多个标准按钮,比如Ok、Cancel、Yes、No等。当用户点击这些按钮时,QDialogButtonBox会发出accepted或rejected信号,这取决于按钮的角色。例如,Ok按钮通常触发accepted,Cancel触发rejected。但clicked信号则会传递被点击的具体QAbstractButton对象,这样用户就可以在槽函数中判断到底是哪个按钮被点击了。 接下来,用户的疑问是,当使用clicked信号时,如何确定点击的是哪个按钮。我需要解释QDialogButtonBox::clicked(QAbstractButton*)信号的使用方法。这个信号会传递被点击的按钮指针,用户可以通过比较这个指针与buttonBox中的标准按钮来判断具体是哪一个。 然后,我需要提供示例代码,展示如何在槽函数中获取被点击的按钮,并检查其角色或类型。比如,可以通过buttonBox->standardButton(button)来获取标准按钮类型,然后根据返回的QDialogButtonBox::StandardButton枚举值判断是Ok还是Cancel,或者其他按钮。 同时,可能需要提到标准按钮与角色之间的关系,例如Ok按钮的角色是AcceptRole,Cancel是RejectRole,这样用户也可以通过角色来判断,而不仅仅是标准按钮类型。但用户的问题中提到他们只知道OK和Cancel,可能他们的buttonBox只包含这两个按钮,但为了全面性,我应该涵盖更多可能性。 还需要注意,如果用户使用的是自定义按钮而不是标准按钮,可能需要不同的处理方式,比如通过设置属性或对象名来标识按钮,然后在槽函数中检查这些属性。但根据用户提供的代码,他们可能使用的是标准按钮,所以重点应放在标准按钮的处理上。 此外,用户可能对信号和槽的连接方式有疑问,特别是为什么第三个连接需要处理QAbstractButton*参数,而前两个不需要。需要解释不同信号传递的参数不同,accepted和rejected信号不传递具体按钮信息,而clicked信号传递按钮对象,因此可以获取更多信息。 最后,需要确保回答结构清晰,分点说明,并提供代码示例,帮助用户理解如何在实际代码中实现按钮的判断。同时,注意使用中文,避免专业术语过于晦涩,必要时进行解释。</think>在 Qt 中处理 `QDialogButtonBox` 的按钮点击时,`clicked` 信号的特殊性在于它能区分具体点击的按钮。以下是详细说明: --- ### 信号机制解析 ```cpp connect(buttonBox, &QDialogButtonBox::clicked, this, &YourClass::onButtonClicked); ``` #### 关键特性 1. **信号参数**:`clicked(QAbstractButton*)` 会传递被点击的 **按钮对象指针** 2. **与标准信号区别**: - `accepted()`:仅当点击 AcceptRole 类按钮(如 OK)时触发 - `rejected()`:仅当点击 RejectRole 类按钮(如 Cancel)时触发 - `clicked()`:点击 **任意按钮** 都会触发,并携带具体按钮信息 --- ### 判断具体按钮的 3 种方法 #### 方法一:通过标准按钮标识(推荐) ```cpp void YourClass::onButtonClicked(QAbstractButton* button) { // 获取按钮的标准类型 QDialogButtonBox::StandardButton stdButton = buttonBox->standardButton(button); switch(stdButton) { case QDialogButtonBox::Ok: qDebug() << "OK 按钮被点击"; break; case QDialogButtonBox::Cancel: qDebug() << "Cancel 按钮被点击"; break; case QDialogButtonBox::Yes: // 处理其他可能存在的按钮 case QDialogButtonBox::No: // ...其他处理... break; default: qDebug() << "非标准按钮被点击"; } } ``` #### 方法二:通过按钮角色判断 ```cpp void YourClass::onButtonClicked(QAbstractButton* button) { // 获取按钮的角色类型 QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(button); if(role == QDialogButtonBox::AcceptRole) { qDebug() << "接受类按钮(如 OK)"; } else if(role == QDialogButtonBox::RejectRole) { qDebug() << "拒绝类按钮(如 Cancel)"; } } ``` #### 方法三:直接对象比对(适用于自定义按钮) ```cpp // 假设已获取按钮指针 QPushButton* customBtn = buttonBox->addButton("自定义", QDialogButtonBox::ActionRole); void YourClass::onButtonClicked(QAbstractButton* button) { if(button == customBtn) { qDebug() << "点击了自定义按钮"; } } ``` --- ### 标准按钮对照表 | 按钮类型 | 触发信号 | 标准角色 | |-----------------------|-------------|--------------------| | OK / Yes / YesToAll | accepted() | AcceptRole | | Cancel / No / Close | rejected() | RejectRole | | Apply / Reset | - | ApplyRole/ResetRole| | Help / Abort | - | HelpRole/AbortRole | --- ### 使用建议 1. **优先使用标准按钮**:通过 `buttonBox->setStandardButtons()` 设置按钮,兼容性更好 ```cpp buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); ``` 2. **混合信号处理**:同时连接 `accepted()` 和 `clicked()` 时,会按连接顺序触发 3. **动态按钮处理**:若动态添加按钮,建议使用 `buttonRole` 判断更可靠 --- **扩展应用**:如果要实现「点击关闭按钮时保存配置」: ```cpp connect(buttonBox, &QDialogButtonBox::clicked, this, [=](QAbstractButton* btn){ if(buttonBox->buttonRole(btn) == QDialogButtonBox::AcceptRole) { saveSettings(); // 点击OK时保存配置 } }); ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值