• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

QT实现图片轮播

qt 搞代码 4年前 (2022-01-06) 22次浏览 已收录 0个评论

这篇文章主要介绍了QT实现图片轮播,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了QT实现图片轮播的具体代码,供大家参考,具体内容如下

UI设计

一个Qlabel控件,一个pushButton 键

废话不多说直接怼代码

.h文件

 #ifndef IMAGES_H #define IMAGES_H #include  #include "ui_images.h" #include  #include  #include  #include  #include  class images : public QMainWindow { Q_OBJECT public: images(QWidget *parent=0); ~images(); private: Ui::imagesClass ui; QTimer *qTimer; int imgNumber; private slots: //显示图片 void showPictureSlot(); }; #endif // IMAGES_H

.cpp文件

 #include "images.h" #pragma execution_character_set("utf-8") images::images(QWidget *parent) : QMainWindow(parent), imgNumber(0) { ui.setupUi(this); //修改标题 this->setWindowTitle("QLabel的显示图片程序:"); //给label设置新的文本 ui.picture_label->setText("未显示图片"); //将label框的内容位于中间. ui.picture_label->setAlignment(Qt::AlignCenter | Qt::AlignHCenter); //设置label框自动填充 //ui.picture_label->setScaledContents(true); //连接信号 与 槽 connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(showPictureSlot())); ui.picture_label->setScaledContents(true); qTimer = new QTimer(); connect(this->qTimer, SIGNAL(timeout()), this, SLOT(showPictureSlot())); qTimer->start(3000); } images::~images() { delete qTimer; } //显示图片 void images::showPictureSlot(){ ++imgNu<strong style="color:transparent">来源gaodai#ma#com搞@@代~&码网</strong>mber; //图片路径(绝对路径拼接) QString path = ":/File/Resources/" + QString::number(imgNumber) + ".png-600"; QPixmap pixmap(path); pixmap.scaled(ui.picture_label->size(), Qt::KeepAspectRatio); ui.picture_label->setPixmap(pixmap); if (3 == imgNumber) { imgNumber = 0; } }

这样简单的图片轮播在Qlabel上就 实现了.

以上就是QT实现图片轮播的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:QT实现图片轮播

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址