• 4123阅读
  • 1回复

滚动标题 [复制链接]

上一主题 下一主题
离线ycj211
 

只看楼主 倒序阅读 楼主  发表于: 2016-04-27
— 本帖被 XChinux 执行加亮操作(2016-04-30) —


#include <QApplication>
#include <QQmlApplicationEngine>
#include <QWidget>
#include <QLabel>
#include <QHBoxLayout>
#include <QTimer>
#include <QDebug>
#include <QTextCodec>
//#pragma execution_character_set("utf-8")
class ScrollText: public QWidget
{
public:
    ScrollText(){
        _scrollText = "欢迎加入我们,一起努力吧,少年!";
        _scrollLabel= new QLabel(this);
        _scrollLabel->resize(200,30);
        QTimer *m_timer = new QTimer(this);
        m_timer->start(500);
        QObject::connect(m_timer,&QTimer::timeout, this,&ScrollText::scrollText);
    }
public slots:
    void scrollText();
private:
    QString  _scrollText;
    QLabel *_scrollLabel;
};
void ScrollText::scrollText()
{
    static int pos = 0;
    if (pos > _scrollText.length())
    {
        pos = 0;
    }
    _scrollLabel->setText(_scrollText.mid(pos));
    qDebug()<<_scrollText.mid(pos)<<"-------";
    pos++;
}

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));
    ScrollText *stxt= new ScrollText;
    stxt->show();
    return app.exec();
}

离线stlcours

只看该作者 1楼 发表于: 2016-05-10
这个创意还挺不错的~
快速回复
限100 字节
 
上一个 下一个