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:
Qt Code:
  1. int mouse_x = event->pos().x();
  2. int mouse_y = event->pos().y();
  3. if (mouse_active==Qt::LeftButton) {
  4. mouse_prev= mouse_active;
  5. mouse_active=Qt::NoButton; // to avoid re-call
  6. event->accept();
  7. // mouse_rx, mouse_ry are private vars . First value is given by mousepress, the nexts from here
  8. this->move(this->geometry().left()+mouse_x-mouse_rx,this->geometry().top() +mouse_y-mouse_ry);
  9. mouse_rx=mouse_x;mouse_ry=mouse_y; // remember
  10. mouse_active=mouse_prev; // restore the button type}
To copy to clipboard, switch view to plain text mode 

Mousepress :
Qt Code:
  1. mouse_active = event->button();
  2. mouse_rx = event->pos().x();
  3. mouse_ry = event->pos().y();
To copy to clipboard, switch view to plain text mode 


Any idea ? (I'm tired to see how so simple thing does not work ....)