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));
    });
相关推荐
love530love44 分钟前
Scoop 完整迁移指南:从 C 盘到 D 盘的无缝切换
java·服务器·前端·人工智能·windows·scoop
消失的旧时光-19431 小时前
C++ 多线程与并发系统取向(二)—— 资源保护:std::mutex 与 RAII(类比 Java synchronized)
java·开发语言·c++·并发
王码码20352 小时前
Flutter for OpenHarmony:Flutter 三方库 bluez 玩转 Linux 风格的蓝牙操作(蓝牙底层互操作)
linux·运维·服务器·前端·flutter·云原生·harmonyos
抓饼先生2 小时前
iceoryx编译和验证
linux·c++·零拷贝·iceoryx
王老师青少年编程2 小时前
2020年信奥赛C++提高组csp-s初赛真题及答案解析(阅读程序第2题)
c++·题解·真题·初赛·信奥赛·csp-s·提高组
你的冰西瓜3 小时前
C++ STL算法——排序和相关操作
开发语言·c++·算法·stl
今儿敲了吗4 小时前
29| 高考志愿
c++·笔记·学习·算法
chilavert3184 小时前
技术演进中的开发沉思-371:final 关键字(中)
java·前端·数据库
2301_816997884 小时前
Vite构建工具
前端