Qt利用代码实现流水灯的效果 您所在的位置:网站首页 动态氛围灯效果图片 Qt利用代码实现流水灯的效果

Qt利用代码实现流水灯的效果

2024-07-09 15:56| 来源: 网络整理| 查看: 265

    用代码实现流水灯的效果

    其实很想实现这种流水灯的效果了,看起来挺酷的,用处也很多,只是开始没有思路不知道怎么去实现,于是在我的超市收银项目中就采用了图片加载的方式进行显示,效果如下图所示:

     由于是动态图片,显示的时候就要用到QMovie进行加载,简单的代码如下所示:

QMovie *move = new QMovie(":/images/splash.gif"); QLabel *label = new QLabel("",0); label->setWindowIcon(QIcon(":/images/main.png")); label->setAttribute(Qt::WA_TranslucentBackground,true);//窗体背景透明 label->setGeometry(510,300,450,100); label->setMovie(move); move->start(); label->setWindowFlags(Qt::FramelessWindowHint); label->show();

    利用动态图片工具制作自己想要的图片,在需要进行加载的时候进行显示即可。这个办法很简单,但是很麻烦,不通用,如果需要显示的字符不一样,就得制作另一张图片了,费时费力。果断放弃。

    另一种方式是直接用代码实现,简单快捷、很通用。效果如下图所示:

    说明此方法是参考别人的。博客地址:http://blog.sina.com.cn/s/blog_a6fb6cc90102vcdn.html

      基本思想是每隔500毫秒显示字符串的变化,时间可以用定时器进行设置,代码如下所示:

设置窗体透明

this->setWindowFlags(Qt::FramelessWindowHint); this->setAttribute(Qt::WA_TranslucentBackground);//窗体背景透明 添加label用于显示文字并对文字设置简单的效果:

this->m_scrollCaptionLabel = new QLabel(this); this->m_scrollCaptionLabel->setToolTip("模拟流水灯效果"); this->m_scrollCaptionLabel->setFont(QFont("Times",30,QFont::Bold)); this->m_scrollCaptionLabel->setStyleSheet("color: blue;"); 实现部分:

m_scrollCaptionStr = QString("欢迎加入我们:技术在于分享、交流 936563422"); QTimer *m_timer = new QTimer(this); QObject::connect(m_timer,SIGNAL(timeout()),this,SLOT(slot_scrollCaption())); QObject::connect(this->m_quitButton,SIGNAL(clicked()),this,SLOT(close())); m_timer->start(500); 槽函数实现部分:

void Widget::slot_scrollCaption() { static int nPos = 0; if (nPos > m_scrollCaptionStr.length()) { nPos = 0; } this->m_scrollCaptionLabel->setText(this->m_scrollCaptionStr.mid(nPos)); ++nPos; }       效果看起来挺不错的,以后可以用在某些特定的场合,多谢“一去二三里”了,在此感谢你……

 

    技术在于分享、交流……

    Email: [email protected]

    QQ:936563422



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有