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));
    });
相关推荐
xlp666hub42 分钟前
Leetcode第七题:用C++解决接雨水问题
c++·leetcode
丁哥1 小时前
99.9%纯AI 做了一个ICO图标生成器(免费 全尺寸 不限文件大小)2ICO.CN欢迎品鉴
前端
兆子龙1 小时前
React Native 完全入门:从原理到实战
前端·javascript
哇哇哇哇1 小时前
vue3 watch解析
前端
SuperEugene1 小时前
Vite 实战教程:alias/env/proxy 配置 + 打包优化避坑|Vue 工程化必备
前端·javascript·vue.js
leafyyuki1 小时前
用 AI 和 SDD 重构 Vue2 到 Vue3 的实践记录
前端·人工智能
德育处主任2 小时前
『NAS』一句话生成网页,在NAS部署UPage
前端·javascript·aigc
前端老兵AI2 小时前
前端工程化实战:Vite + ESLint + Prettier + Husky 从零配置(2026最新版)
前端·vite
bluceli2 小时前
浏览器渲染原理与性能优化实战指南
前端·性能优化
张元清2 小时前
Astro 6.0:被 Cloudflare 收购两个月后,这个"静态框架"要重新定义全栈了
前端·javascript·面试