zoukankan      html  css  js  c++  java
  • 文字左移

    如果文字很多在屏幕中一次性绘制坑能造成卡屏,文字移动不流畅,所以要对文字分块进行移动。

    移动方法:

    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;
                }
            }
        }
  • 相关阅读:
    为Android编译bash
    编译toybox
    RGB信仰灯
    如何用Fiddler抓BlueStacks的HTTPS包
    Adobe Acrobat快捷方式
    [MS-SHLLINK]: Shell Link (.LNK) Binary File Format
    BZOJ 3993 星际战争
    BZOJ 3996 线性代数
    BZOJ 1797 最小割
    BZOJ 2726 任务安排
  • 原文地址:https://www.cnblogs.com/jck34/p/3844446.html
Copyright © 2011-2022 走看看