Thanks for your answers so far. This is basicly what i tried before. Your example works fine for me and I agree with you that one could solve the issue of fast mouse moving with a timer. But if I try to implement this in my program it does not work. I had a look at the debugger and i think my geometry does not work properly. And I think this might be because i did something wrong with the derivation of my classes.
Would it help if I post my whole code here or what informations are required to help me with this issue?
Edit:
I have the problem that the upper and the left margin are ca. as twice as big as the lower and the right margin. Anyone has an idea why this is the case?
int marginThickness = 30;
int globalX = event->globalX();
int globalY = event->globalY();
int geoX = geometry().x();
int geoY = geometry().y();
QPoint newPos
(globalX, globalY
);
if (globalY < globalGeo.y() + marginThickness){
newPos.setY(globalGeo.y() + marginThickness);
} else if (globalY > globalGeo.y() + height() - marginThickness){
newPos.setY(globalGeo.y() + height() - marginThickness);
}
if (globalX < globalGeo.x() + marginThickness){
newPos.setX(globalGeo.x() + marginThickness);
} else if (globalX > globalGeo.x() + width() - marginThickness){
newPos.setX(globalGeo.x() + width() - marginThickness);
}
this->cursor().setPos(newPos);
}
void MapView::mouseMoveEvent(QMouseEvent *event){
int marginThickness = 30;
int globalX = event->globalX();
int globalY = event->globalY();
int geoX = geometry().x();
int geoY = geometry().y();
QPoint globalGeo (this->mapToGlobal(QPoint(geoX, geoY)));
QPoint newPos(globalX, globalY);
if (globalY < globalGeo.y() + marginThickness){
newPos.setY(globalGeo.y() + marginThickness);
} else if (globalY > globalGeo.y() + height() - marginThickness){
newPos.setY(globalGeo.y() + height() - marginThickness);
}
if (globalX < globalGeo.x() + marginThickness){
newPos.setX(globalGeo.x() + marginThickness);
} else if (globalX > globalGeo.x() + width() - marginThickness){
newPos.setX(globalGeo.x() + width() - marginThickness);
}
this->cursor().setPos(newPos);
}
To copy to clipboard, switch view to plain text mode
Bookmarks