Qt 基本对话框的调用

1.获取标准文件对话框用户选择文件的路径

 QString s = QFileDialog::getOpenFileName(this,"open file dialog","/","C++ file(*.cpp)::C file(*.c)::Head files(*.h)");
 QLineEdit *lineEdit;
 lineEdit->setText(s);

2.获取标准文件对话框用户选择文件夹的路径

QString s = QFileDialog::getExistingDirectory(this, "choose src Directory","/");
QLineEdit *lineEdit;
lineEdit->setText(s);

3.获取标准颜色对话框用户选择的颜色

QColor c = QColorDialog::getColor(Qt::blue);
QFrame *frame;
//功能检查变量c是否已经实例化即实例变量c的值是否是个有效的对象句柄
if(c.isValid())
{
   frame->setPalette(QPalette(c));
   frame->setFrameShape(QFrame::Box);
   frame->setAutoFillBackground(true);
   frame->setPalette(QPalette(c));
}

4.获取标准字体对话框用户选择的字体

bool ok;
QFont f = QFontDialog::getFont(&ok);
QLineEdit *lineEdit;
if(ok)
{
    lineEdit->setFont(f);
    lineEdit->setText(tr("Welcome!"));
}

5.消息对话框
Question消息框

switch (QMessageBox::question(this,tr("Question消息框"),tr("是否结束?"),QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok)) 
{
case QMessageBox::Ok:
    ;
    break;
case QMessageBox::Cancel:
    ;
    break;
default:
    break;  
}

Warning消息框

switch (QMessageBox::warning(this,tr("Warning消息框"),tr("是否保存修改?"),QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,QMessageBox::Save)) 
{
case QMessageBox::Save:
    ;
    break;
case QMessageBox::Discard:
    ;
    break;
case QMessageBox::Cancel:
    ;
    break;
default:
    break;  
}

Critical消息框

QMessageBox::critical(this,tr("Critical消息框"),tr("这是一个Critical消息框测试!"));

About 消息框

QMessageBox::about(this,tr("About消息框"),tr("这是一个About消息框测试!"));

About Qt消息框

QMessageBox::aboutQt(this,tr("About Qt消息框"));

你可能感兴趣的:(Qt学习笔记)