class creepingLine: public QObject{ Q_OBJECTprivate: QLabel *mOutWidget; QString mText; int mDelay; int mId; inline void rollLine() { mText.prepend(mText.right(1)); mText = mText.mid(0, mText.length() - 1); }protected: inline void timerEvent(QTimerEvent*) { rollLine(); mOutWidget->setText(mText); }public: inline creepingLine(QLabel *iOutWidget, QString iText, int iDelay = 1000) : mOutWidget(iOutWidget), mText(iText), mDelay(iDelay) {};public slots: inline void start() { mId = startTimer(mDelay); }; inline void stop() { if (mId) killTimer(mId); };};
int QFontMetrics::width ( const QString & text, int len = -1 ) constReturns the width in pixels of the first len characters of text. If len is negative (the default), the entire string is used.Note that this value is not equal to boundingRect().width(); boundingRect() returns a rectangle describing the pixels this string will cover whereas width() returns the distance to where the next string should be drawn.See also boundingRect().