C++ QT 打开图片

cpp 复制代码
    QGridLayout *g = new QGridLayout(this);
    setLayout(g);

//    g->addWidget(new QPushButton("Hello",this),1,2,0,20);
//    g->addWidget(new QPushButton("Hello",this),0,0);
//    g->addWidget(new QPushButton("Hello",this),0,1);
//    g->addWidget(new QPushButton("Hello",this),0,2);

    QLineEdit *line = new QLineEdit(this);
    g->addWidget(line,3,0);
    QLabel *label = new QLabel("Hello",this);

    g->addWidget(label,0,0);

    auto b = new QPushButton("打开图片",this);

    g->addWidget(b,3,1);

    this->resize(480,320);



    connect(b,&QPushButton::clicked,[this,line,label](bool i){
           qDebug()<<"test"<<i;
           auto filepath = QFileDialog::getOpenFileName(this,"选择图片",line->text(),"Images(*.png *.jpg *.bmp)");
           qDebug() << filepath;
           line->setText(filepath);

           label->setPixmap(QPixmap(filepath));
    });
相关推荐
B1acktion1 分钟前
2.7.希尔排序——让插入排序先大步走,再小步收尾
c++·算法·排序算法
.生产的驴5 分钟前
Vue3 超大字体font-slice按需分片加载,极速提升首屏速度, 中文分片加载方案,性能优化
前端·vue.js·windows·青少年编程·性能优化·vue·rescript
原来是猿5 分钟前
Linux进程信号详解(一):信号快速认识
linux·c++·算法
醉城夜风~12 分钟前
C++函数参数的默认值及其使用场景
开发语言·c++·算法
打瞌睡的朱尤13 分钟前
CSS复习
前端·css
炘爚16 分钟前
C++(四大设计模式——单例/工厂/抽象工厂/代理)
c++
迷途之人不知返16 分钟前
string(2)
c++
tankeven17 分钟前
HJ162 ACM中的AC题
c++·算法
irpywp18 分钟前
Boneyard:基于组件映射的骨架屏方案
前端·ui·github
276695829220 分钟前
zp_stoken 算法风控分析
java·前端·javascript·python·web逆向·boss直聘·zp_stoken