首页 > 代码库 > Qt的卡拉OK歌词效果
Qt的卡拉OK歌词效果
先上图一张..
驳壳地址:http://blog.csdn.net/robertkun
实现卡拉OK效果, 主要是使用了QPainter的叠加,
pTmp.setCompositionMode(QPainter::CompositionMode_Source); pTmp.fillRect(QRect(0, 0, paintw, rtText.height()), QBrush(Qt::white)); pTmp.fillRect(QRect(0, 0, mPrecent, rtText.height()), QBrush(Qt::blue)); pTmp.setCompositionMode(QPainter::CompositionMode_DestinationIn); pTmp.drawImage(0, 0, pmMask); pTmp.setCompositionMode(QPainter::CompositionMode_DestinationOver);
主要函数:
void testLyrics::DrawLyric(QPainter &p, const QRect& rt) { p.setBrush(Qt::darkGray); p.drawRect(rect()); const QString strLyric = mCurLyrics.lyric; QFont m_ftLyric(QString::fromLocal8Bit("微软雅黑"), 24, QFont::Bold); QPainter pTmp; QFontMetrics fm(m_ftLyric); QSize textSize = fm.size(Qt::TextSingleLine, strLyric); QRect textRect(QPoint(0,0),textSize); int paintw = textSize.width(); int playedW = textSize.width()*0.5; QRect rtText = rect(); // pTmp.setRenderHints(QPainter::TextAntialiasing, true); QImage pmMask(paintw, rtText.height(),QImage::Format_ARGB32); pmMask.fill(Qt::transparent); if (pTmp.begin(&pmMask)) { pTmp.setFont(m_ftLyric); pTmp.setPen(Qt::black); pTmp.drawText(pmMask.rect(), strLyric); } pTmp.end(); QImage pmFG(paintw, rtText.height(),QImage::Format_ARGB32); if (pTmp.begin(&pmFG)) { pTmp.setCompositionMode(QPainter::CompositionMode_Source); pTmp.fillRect(QRect(0, 0, paintw, rtText.height()), QBrush(Qt::white)); pTmp.fillRect(QRect(0, 0, mPrecent, rtText.height()), QBrush(Qt::blue)); pTmp.setCompositionMode(QPainter::CompositionMode_DestinationIn); pTmp.drawImage(0, 0, pmMask); pTmp.setCompositionMode(QPainter::CompositionMode_DestinationOver); // shadow pTmp.setFont(m_ftLyric); pTmp.setPen(QColor(0,0,0,0x80)); pTmp.drawText(pmMask.rect(), strLyric); } pTmp.end(); p.drawImage(rtText.left(), rtText.top(), pmFG); }
http://download.csdn.net/detail/robertkun/7297947
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。