Qt,鼠标跳过,不更新每个像素,mouseMoveEvent() [英] Qt, Mouse skipping, not updating every pixel, mouseMoveEvent()

查看:563
本文介绍了Qt,鼠标跳过,不更新每个像素,mouseMoveEvent()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个简单的油漆程序。
它似乎Qt(和KDE)将是一个简单的方法来实现它。
我发现Qt很容易使用,但现在我遇到了一个问题。

I working on a simple paint program. It seemed Qt (and KDE) would be a easy way to implement it. I find Qt quite easy to work with, but now I have hit a problem.

当我在我的程序绘制的东西,鼠标跳过,如果我移动鼠标快速。

When I draw something in my program the mouse skips if I move the mouse to fast.

像这样:



怀疑是一个长字符串。

like this:

It susposed to be like one long string.

使用mouseMoveEvent()在按下鼠标左键时绘制一个像素到我的图像。
我调用setMouseTracking(true);因此只要移动鼠标,就应该调用该事件。

I'm using mouseMoveEvent() to draw a pixel to my image when the left mouse button is pressed down. I have called setMouseTracking(true); so the event should be called as long as I move the mouse.

void camoMaker::mouseMoveEvent(QMouseEvent *ev)
{
    if(ev->state()==Qt::LeftButton)
    {
    	QPoint mPoint=ev->pos();
    	mPoint.setX(mPoint.x()-80);
    	drawPoint(mPoint);
    }
}

camoMaker是主要部件。

drawPoint()在绘制区域的QWidget上使用QPainter在内部QImage上绘制像素。

camoMaker is the main widget.
drawPoint() draws a pixel on both a internal QImage and using QPainter on a QWidget thats the drawing area.

在我看来,mouseMoveEvent

It seems to me that either mouseMoveEvent() isn't called for every pixel the mouse moves or that the mouse actually just skips some pixel.

我理解它可能只是它的工作原理,而不是Qt的错误,但X11或者操作系统如何处理鼠标位置/输入。

I understand that it might just how it works and not Qt fault but X11 or how the OS handle mouse position/input.

如果是这样,我将如何解决它,我应该尝试从2点内部注册?

If so how would I go about to fix it, should I try to interpolate from 2 points that gets registered?

推荐答案

在大多数操作系统上,鼠标移动时不会对每个像素发生鼠标事件。消息处理程序(包括KDE / linux)重复显示鼠标移动,但像素通常会被跳过。

Mouse events don't occur for each pixel as the mouse moves, on most operating systems. The message handlers (including KDE/linux) repeatedly show mouse movements, but pixels will often be skipped.

您需要跟踪最后一个像素位置,一条线,或在最后一个位置和当前位置之间添加额外点。

You'll need to track the last pixel location, and either draw a line, or add extra points in between the last position and the current position.

这篇关于Qt,鼠标跳过,不更新每个像素,mouseMoveEvent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆