您当前的位置: 首页 > 

令狐掌门

暂无认证

  • 0浏览

    0关注

    513博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

QLabel自适应显示图片

令狐掌门 发布时间:2020-03-05 22:19:55 ,浏览量:0

        在Qt开发时,如果不知道怎么实现功能,可以先看看相关类的代码,例如,要实现QLabel显示图片,如果没做过肯定不知道怎么写,看看QLabel的代码:

public Q_SLOTS:
    void setText(const QString &);  //设置文本
    void setPixmap(const QPixmap &);  //设置pixmap
#ifndef QT_NO_PICTURE
    void setPicture(const QPicture &);
#endif
#if QT_CONFIG(movie)
    void setMovie(QMovie *movie);
#endif
    void setNum(int);    //设置整数
    void setNum(double);
    void clear();

         查看Qt文档可知,用setPixmap可以显示图片,解释如下:

         This property holds the label's pixmap,If no pixmap has been set this will return nullptr.  Setting the pixmap clears any previous content. The buddy shortcut, if any, is disabled.

         写段代码试试看

QString path = QString("D:\\TestFiles\\123.jpg");
QImage img;
img.load(path);
QPixmap px
关注
打赏
1652240117
查看更多评论
立即登录/注册

微信扫码登录

0.0394s