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));
    });
相关推荐
王老师青少年编程4 小时前
2022年CSP-X复赛真题及题解(T1:独木桥)
c++·真题·csp·信奥赛·复赛·独木桥·csp-x
JS菌4 小时前
Skills 动态加载系统:让 AI Agent 按需获取领域知识
前端·人工智能·后端
weedsfly4 小时前
Sass 代码复用完全指南:从变量到模块化
前端
张拭心4 小时前
Android 17 新特性:后台音频交互限制加强
android·前端
张拭心5 小时前
Android 17 新特性:ProfilingManager 新触发器
android·前端
小短腿的代码世界5 小时前
Qt对象树析构链与智能指针协同:零泄漏内存管理架构
开发语言·qt·架构
weixin_471383035 小时前
Taro-03-页面生命周期
前端·javascript·taro
张拭心5 小时前
Android 17 新特性:MessageQueue 无锁实现
android·前端
Asize5 小时前
数组数据结构底层:从灵活到陷阱
前端·javascript·算法