码迷,mamicode.com
首页 > 其他好文 > 详细

Qt的卡拉OK歌词效果

时间:2014-05-07 04:22:26      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:qt   卡拉ok效果   

先上图一张..

bubuko.com,布布扣


驳壳地址: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

Qt的卡拉OK歌词效果,布布扣,bubuko.com

Qt的卡拉OK歌词效果

标签:qt   卡拉ok效果   

原文地址:http://blog.csdn.net/robertkun/article/details/25059463

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!