文字左移
如果文字很多在屏幕中一次性绘制坑能造成卡屏,文字移动不流畅,所以要对文字分块进行移动。
移动方法:
1. 设置mDrawPos = width();即绘画起点在最右边。
2. 在计时器中设置mDrawPos -= mMoveSpeed,当 mDrawPos < -mTotalWidth时结束
3. 在paintEvent中根据mDrawPos计算出每一段实际文字的drawpos进行绘制
部分代码如下:
timerEvent中:
if (mMoveDirection == pvprRssTextPlayInfo::RightToLeft) { //由右往左移 if (mTextOrientation == pvprRssTextPlayInfo::Normal) { mDrawPos -= mMoveSpeed; if(mDrawPos < -mTextTotalWidth) { finished = true; } } } repaint(); if (mPlayTimeType == pvprRssTextPlayInfo::PlayTime) { if (mStopPlayTime <= QDateTime::currentDateTime()) { mIsPlaying = false; OnPlayInfoFinished(); } }
paintEvent中:
if (mMoveDirection == pvprRssTextPlayInfo::RightToLeft) { //从右往左移 if (mTextOrientation == pvprRssTextPlayInfo::Normal) { int drawPos = mDrawPos; foreach(pvprRssTextInfo rssTextInfo,mRssTextInfoList) { if(drawPos < -rssTextInfo.textWidth || drawPos > width()) //对于屏幕之外的文字不绘制 { drawPos += rssTextInfo.textWidth; continue; } painter.drawText(QRect(drawPos,0,rssTextInfo.textWidth,height()),mTextFlag,rssTextInfo.text); drawPos += rssTextInfo.textWidth; } } }