ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

【Qt-QMessageBox-】

2026/8/15 23:22:32 拓冰建站 浏览量
【Qt-QMessageBox-】

Qt编程指南

  • ■ QMessageBox

■ QMessageBox

示例一:
#include <QApplication>
#include <QMessageBox>
#include <QPushButton>
#include <QDebug>
int main(int argc, char *argv[])
{QApplication a(argc, argv);QMessageBox MBox;MBox.setWindowTitle("QMessageBox自定义对话框");MBox.setText("这是一个自定义的对话框");MBox.setIconPixmap(QPixmap("C:\\Users\\xiexuewu\\Desktop\\icon_c.png"));QPushButton *agreeBut = MBox.addButton("同意", QMessageBox::AcceptRole);MBox.exec();if (MBox.clickedButton() == (QAbstractButton*)agreeBut) {//在 Qt Creator 的输出窗口中输出指定字符串qDebug() << "用户点击了同意按钮";}return a.exec();
}//按钮样式设置,
QMessageBox QPushButton{
border: 1px solid black; border-radius: 10px;
}box.setStyleSheet("QLabel{""min-width: 300px;""min-height: 300px; ""font-size:20px;""}""QPushButton {""background-color:#89AFDE;"" border-style: outset;"" border-width: 10px;"" border-radius: 20px;"" border-color: beige;"" font: bold 15px;"" min-width: 15em;"" min-height: 5em;""}""");//此处设置弹窗的字体和按钮属性示例二:
QMessageBox box;//设置文本框的大小和颜色
box.setStyleSheet("QLabel{""min-width: 300px;""min-height: 150px; ""font-size: 16px;""color: red;"
"}");
box.setText("这是一个QMessageBox");
box.setWindowTitle("关于");
box.exec();