Qt - 自定义光标点击样式

来由

     上周右手大拇指被自家车门夹伤,, 无奈被迫拔甲手术,,以至疼痛不能发文、禁食等等造成很多不便,哎 再次敲钟稳稳的幸福。。而后就连心念的手游农药也,,看看朋友直播缓解度日。注意到在录制屏幕时操控软件的一些特效,故有了此篇文章。疼痛让我恨恨不平,代码与当前文字很多地方不尽人意 但还是出了点东西,希望观友喜欢。近期将内容方向侧重文字面。
     下面,继续。。

正文

     真相只有一个:
在这里插入图片描述
     如上图,颜色、宽度不闲扯了,捡一些比较实在的说说流程。"圈圈"特效其实就是绘制了一个圆,但这个圆的半径是根据时间变化逐渐放大直到够大消失,我们要做的是控制好半径扩大与位置的移动仅此而已。"卍文"特效,那么就相比下简单一点,先是记录了点击位置然后按位置画形状,这里需要注意点的是坐标位置的变换和结束消失配合时间自动增加大小。"弹文"特效嘛,比上面两个就更为嗨皮了,开始初始化一些字串组 需要用的时候随机拿过来其中一个,记录一哈点击位置 在这个位置把字串弄出来,然后通过该位置与时间变化移动消失便可。大致听懂了,基本也就完胜ko。下面上码。。

Ripple::Ripple(QWidget *parent /*= nullptr*/)
{
	mouseReleaseFlag = false;
	RippleValue = 0;

	MaxValue = 32;
	Width = 1;
	Color = Qt::black;
	tags << "hello,world!" << QString::fromLocal8Bit("拔甲大夫真tm兴奋。。") << QString::fromLocal8Bit("拔甲大夫真tm") << QString::fromLocal8Bit("青葱岁月。");
}

void Ripple::mouseReleaseEvent(QMouseEvent *event)
{
	if (!mouseReleaseFlag)
	{
		mouseReleaseFlag = true;
		mouseReleasePoint = event->pos();
		tag = tags[qrand() % tags.count()];
		TimerId = startTimer(100);
	}
}

void Ripple::paintEvent(QPaintEvent *event)
{
	QPen pen;
	pen.setColor(Color);
	pen.setWidth(Width);

	QFont font("微软雅黑", 12, QFont::Normal);

	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setPen(pen);
	if (rippleStyle == Ripple::RippleStype::CircleSymbol)
	{
		painter.drawEllipse(mouseReleasePoint, RippleValue, RippleValue);
	}
	else if (rippleStyle == Ripple::RippleStype::WanSymbol)
	{
		if (RippleValue)
		{
			painter.save();
			painter.translate(mouseReleasePoint);
			painter.drawLine(0, 0, -RippleValue / 2, 0);
			painter.drawLine(-RippleValue / 2, 0, -RippleValue / 2, -RippleValue / 2);
			painter.drawLine(0, 0, RippleValue / 2, 0);
			painter.drawLine(RippleValue / 2, 0, RippleValue / 2, RippleValue / 2);
			painter.drawLine(0, 0, 0, -RippleValue / 2);
			painter.drawLine(0, -RippleValue / 2, RippleValue / 2, -RippleValue / 2);
			painter.drawLine(0, 0, 0, RippleValue / 2);
			painter.drawLine(0, RippleValue / 2, -RippleValue / 2, RippleValue / 2);
			painter.restore();
		}
	}
	else if (rippleStyle == Ripple::RippleStype::TagSymbol)
	{
		painter.save();
		painter.translate(mouseReleasePoint);
		painter.setFont(font);
		if(RippleValue)
			painter.drawText(0, -RippleValue, tag);
		painter.restore();
	}
}

源码

源码正在上传,请等待。。

关注

微信公众号搜索"Qt_io_"或"Qt开发者中心"了解更多关于开发知识.。

笔者 - jxd

发布了43 篇原创文章 · 获赞 0 · 访问量 2998

猜你喜欢

转载自blog.csdn.net/automoblie0/article/details/102981764
今日推荐