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));
    });
相关推荐
运维@小兵几秒前
vue配置子路由,实现点击左侧菜单,内容区域显示不同的内容
前端·javascript·vue.js
海绵宝宝贾克斯儿34 分钟前
C++中如何实现一个单例模式?
开发语言·c++·单例模式
Epiphany.55637 分钟前
素数筛(欧拉筛算法)
c++·算法·图论
龙湾开发39 分钟前
计算机图形学编程(使用OpenGL和C++)(第2版)学习笔记 10.增强表面细节(二)法线贴图
c++·笔记·学习·图形渲染·贴图
koiy.cc44 分钟前
记录:echarts实现tooltip的某个数据常显和恢复
前端·echarts
whoarethenext1 小时前
c/c++的opencv的轮廓匹配初识
c语言·c++·opencv
爱吃涮毛肚的肥肥(暂时吃不了版)1 小时前
项目班——0510——JSON网络封装
c++·算法·json
一只专注api接口开发的技术猿1 小时前
企业级电商数据对接:1688 商品详情 API 接口开发与优化实践
大数据·前端·爬虫
GISer_Jing1 小时前
[前端高频]数组转树、数组扁平化、深拷贝、JSON.stringify&JSON.parse等手撕
前端·javascript·json
apocelipes1 小时前
使用libdivide加速整数除法运算
c语言·c++·性能优化·linux编程