I am sub-classing a QLabel and am trying to rotate it as the user drags (or rotates) an image with the mouse. Currenty I am just rotating clock-wise with every mouse moved event:
void RotoTest::slotMouseMoved()
{
currentRotation += 1;
rotate(currentRotation % 360);
}
void RotoTest::rotate(int degree)
{
QPixmap pixmap(originalPixmap);
QPixmap rotatedMap(pixmap.size());
QPainter p(&rotatedMap);
p.translate(pixmap.size().width() / 2, pixmap.size().height() / 2);
p.rotate(degree);
p.translate(-pixmap.size().width() / 2, -pixmap.size().height() / 2);
p.drawPixmap(0, 0, pixmap);
this->setPixmap(rotatedMap);
}
This works and rotates, but the problem is that the image becomes very laggy, jittery and unresponsive, especially the quicker or longer the mouse is moved for a given instance. I suspect this is happening due to the large amount of signals being sent when the mouse moves. Does anybody have any suggestions for a way for a nice smooth rotation? I am looking for the image to rotate as nicely as the QDial does.
It is not clear to me without seeing more code, but possibly it is too many events piling up. If that’s the case, then 1) it’s a surprise since Qt is supposed to quietly take care of compressing many identical events into a few and 2) you can do it yourself by throttling calls to update() in your slot code handling the input event. (Or, since you’re subclassing QLabel, it would go somewhere…?)
See http://qt-project.org/forums/viewthread/12257 for explanation and code.
Then again, this could be barking up the wrong tree entirely. That’s why we have downvote buttons 😉