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(); }
|
|