tonnot
19th July 2011, 10:13
I have a simple code (i think) to move a simple Widget placed at the central-widget of a window. I have subclass the mouseevents to do the work but it does not work properly.
( the widget flikks and on every movement of 1 pixel the mouse is 1 pixel from it have to be placed... )
Mousemove:
int mouse_x = event->pos().x();
int mouse_y = event->pos().y();
if (mouse_active==Qt::LeftButton) {
mouse_prev= mouse_active;
mouse_active=Qt::NoButton; // to avoid re-call
event->accept();
// mouse_rx, mouse_ry are private vars . First value is given by mousepress, the nexts from here
this->move(this->geometry().left()+mouse_x-mouse_rx,this->geometry().top() +mouse_y-mouse_ry);
mouse_rx=mouse_x;mouse_ry=mouse_y; // remember
mouse_active=mouse_prev; // restore the button type}
Mousepress :
mouse_active = event->button();
mouse_rx = event->pos().x();
mouse_ry = event->pos().y();
Any idea ? (I'm tired to see how so simple thing does not work ....)
( the widget flikks and on every movement of 1 pixel the mouse is 1 pixel from it have to be placed... )
Mousemove:
int mouse_x = event->pos().x();
int mouse_y = event->pos().y();
if (mouse_active==Qt::LeftButton) {
mouse_prev= mouse_active;
mouse_active=Qt::NoButton; // to avoid re-call
event->accept();
// mouse_rx, mouse_ry are private vars . First value is given by mousepress, the nexts from here
this->move(this->geometry().left()+mouse_x-mouse_rx,this->geometry().top() +mouse_y-mouse_ry);
mouse_rx=mouse_x;mouse_ry=mouse_y; // remember
mouse_active=mouse_prev; // restore the button type}
Mousepress :
mouse_active = event->button();
mouse_rx = event->pos().x();
mouse_ry = event->pos().y();
Any idea ? (I'm tired to see how so simple thing does not work ....)