首页 > 其他 > 详细

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

时间:2019-04-22 14:01:09      阅读:533      评论:0      收藏:0      [点我收藏+]

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();
        }

技术分享图片

 

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

原文:https://www.cnblogs.com/xiangtingshen/p/10749323.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!