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));
    });
相关推荐
ShineWinsu2 小时前
对于Qt:QLCDNumber常见属性以及QTimer的解析
服务器·数据库·c++·qt·gui·qtimer·qlcdnumber
xiaoye-duck2 小时前
《C++ 工具库实战》C++ 解析利器 JsonCpp:从基础使用到封装简易 JSON 工具
c++·json·第三方库
陈随易2 小时前
一个网吧网管,做了个网页,卖了 5000 万
前端·后端·程序员
dialect_10 小时前
KMP算法
开发语言·c++·算法
jktantan10 小时前
Vue keep-alive 切标签后滚动位置回顶?因为 onDeactivated 里读到的 scrollTop 是 0
前端·javascript·vue.js
2601_9628857211 小时前
quotes 字段全解:涨跌幅、振幅、换手率的口径与单位
java·前端·spring
听风吹等浪起12 小时前
第26章:ViT+InceptionDW+FocalLoss改进|CT骨折影像二分类完整Pytorch实现(含PyQt5推理GUI)
pytorch·qt·分类
excel12 小时前
encodeURI 和 encodeURIComponent 有什么区别?
前端
前端精髓12 小时前
调用openrouter的免费API模型
java·前端·javascript
ShineWinsu12 小时前
对于Qt:QRadioButton常见属性以及QButtonGroup的解析
数据库·c++·qt·microsoft·gui·qradiobutton·qbuttongroup