【Qt-QMessageBox-】

Qt编程指南

  • ■ QMessageBox

■ QMessageBox

示例一:
#include 
#include 
#include 
#include 
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();

你可能感兴趣的:(#,Qt,qt)