zoukankan      html  css  js  c++  java
  • QT学习笔记5

    Qt标准对话框之QFileDialog

    //QString path=QFileDialog::getOpenFileName(this,tr("open image"),".",tr("Image file(*.jpg *.png *bmp)"));

        QFileDialog *fileDialog=new QFileDialog(this);
        fileDialog->setWindowTitle(tr("open image"));
        fileDialog->setDirectory(tr("."));
        fileDialog->setFilter(tr("Image file(*.jpg *.png *bmp)"));
    
        if (fileDialog->exec()!=QDialog::Accepted)
        {
            QMessageBox::information(NULL,tr("Path"),tr("open file failed"));
        }else
        {
            QString path=fileDialog->selectedFiles()[0];
           QMessageBox::information(NULL,tr("Path"),tr("You selected ")+path);
        }

    Qt标准对话框之QColorDialog

     
    QColor color=QColorDialog::getColor(Qt::blue,this);
    QString msg=QString("r: %1, g: %2, b:%3").arg(QString::number(color.red()),QString::number(color.green()),QString::number(color.blue()));
    QMessageBox::information(NULL,tr("COLOR"),msg);

    QString 用法 需要QString("r: %1, g: %2, b: %3")创建了一个QString对象。占位符的替换需要使用QString的arg()函数。QString::number()函数,这也是QString的一个static函数,作用就是把int、double等值换成QString类型。

    Qt标准对话框之QMessageBox

    QMessageBox::critical(NULL,tr("warning"),tr("this is something worong"),QMessageBox::Yes|QMessageBox::No,QMessageBox::No);

    设置图标

    QMessageBox message(QMessageBox::NoIcon,"title","content");
        message.setIconPixmap(QPixmap("H:\for home\learningQT\11\Open.png")); 
        message.exec();

    消息对话框选择

     1     QMessageBox::StandardButton rb=QMessageBox::critical(NULL,tr("warning"),tr("this is something worong"),QMessageBox::Yes|QMessageBox::No,QMessageBox::No);
     2     if (rb==QMessageBox::Yes)
     3     {
     4        QMessageBox::information(NULL,tr("Path"),tr("Y"));
     5     }else
     6     {
     7         QMessageBox::information(NULL,tr("Path"),tr("N "));
     8     }
     9     QMessageBox message(QMessageBox::NoIcon,"title","content",QMessageBox::Yes|QMessageBox::No,NULL);
    10     message.setIconPixmap(QPixmap("H:\for home\learningQT\11\Open.png")); 
    11     
    12     if (message.exec()==QMessageBox::No)
    13     {
    14        QMessageBox::information(NULL,tr("Path"),tr("N "));
    15     }

    Qt标准对话框之QInputDialog

    bool isok;
        QString text=QInputDialog::getText(NULL,"input dialog","Please input your commen",QLineEdit::Normal,"my name",&isok);
         QMessageBox::information(NULL,tr("Path"),"Your comment is: <b>" + text + "</b>");
  • 相关阅读:
    c# 图文添加文字斜水印 优化
    c# 图文添加文字斜水印
    c# bool类型和int类型的互转
    在xcode中新建项目使用Image.xcassets时不显示自定义图片
    修改SearchBar的取消按钮Cancel为中文
    生成新订单号
    java LineNumberReader的使用
    深入浅出多线程——ReentrantLock (二)
    深入浅出多线程——ReentrantLock (一)
    深入浅出多线程——线程基础篇
  • 原文地址:https://www.cnblogs.com/love6tao/p/5198390.html
Copyright © 2011-2022 走看看