查看完整版本: [-- 滚动标题 --]

QTCN开发网 -> Qt代码秀 -> 滚动标题 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

ycj211 2016-04-27 12:13

滚动标题



#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 2016-05-10 22:47
这个创意还挺不错的~


查看完整版本: [-- 滚动标题 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled