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));
    });
相关推荐
风清扬_jd14 分钟前
libtorrent-rasterbar-2.0.11编译说明
c++·windows·p2p
u01092727115 分钟前
C++中的RAII技术深入
开发语言·c++·算法
彷徨而立1 小时前
【C/C++】strerror、GetLastError 和 errno 的含义和区别?
c语言·c++
誰能久伴不乏1 小时前
【Qt实战】工业级多线程串口通信:从底层协议设计到完美收发闭环
linux·c++·qt
2401_832131951 小时前
模板错误消息优化
开发语言·c++·算法
金枪不摆鳍1 小时前
算法--二叉搜索树
数据结构·c++·算法
liu****1 小时前
4.Qt窗口开发全解析:菜单栏、工具栏、状态栏及对话框实战
数据库·c++·qt·系统架构
近津薪荼1 小时前
优选算法——双指针6(单调性)
c++·学习·算法
m0_748229991 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
helloworldandy2 小时前
高性能图像处理库
开发语言·c++·算法