(六)QDialog,QMessageBox,QFileDialog,QColorDialog颜色,QFontDialog字体

QDialog

对话框:

1.模态对话框

QDialog dlg(this);
 // 显示模态对话框 exec ,后面的不可操作
dlg.exec(); // 阻塞

2.非模态对话框

QDialog *dlg = new QDialog(this);
// 显示非模态对话框 show()
// 设置对话框属性
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show(); // 非阻塞

QMessageBox

Static Public Members:question,information,warnnig,....

    connect(ui->actionOpen, &QAction::triggered, this, [=]()
    {
        if(QMessageBox::Ok == QMessageBox::question(this, "error", "系统文件错误!!!",
                                                   QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel))
        {
           QDialog dlg(this);
            // 显示模态对话框 exec
           dlg.exec(); // 阻塞

       }

    });

QFileDialog

    connect(ui->actionOpen, &QAction::triggered, this, [=]()
    {
        QString name = QFileDialog::getOpenFileName(this, "打开文件", "D:\\", "Image (*.jpg *.png)");
        qDebug() << name.toUtf8().data();

    });

QColorDialog

        QColor color = QColorDialog::getColor();
        qDebug() << color.red() << color.green() << color.blue();

QFontDialog

        bool ok;
        QFont font = QFontDialog::getFont(&ok, QFont("华文彩云"), this, "我的字体设置");
        if(ok)
        {
            qDebug() << font.family().toUtf8().data() << font.italic() << font.pointSize() << font.bold();
        }

猜你喜欢

转载自www.cnblogs.com/xiangtingshen/p/10749323.html