netmat
27th May 2010, 10:09
there are widgets in my app which are derived from a custom widget in my app. now i want the widgets not to move beyond the visible screen area.because if it moves beyond that the user will not be able to drag it back and close it through close button.
how to achieve that. I tried to do that as in following code in the event filter of the custom widget:
//check that the new position is with in available range
QDesktopWidget *desktop = QApplication::desktop();
QRect desktopRect = desktop->availableGeometry();
if(desktopRect.contains(keyEvent->globalPos())){
this->move(this->pos() + (keyEvent->globalPos() - mLastMousePosition));
mLastMousePosition = keyEvent->globalPos();
return true;
}
This is not working. Where I am doing wrong.
Pls, show me a way to acheive this.
Thanks.
how to achieve that. I tried to do that as in following code in the event filter of the custom widget:
//check that the new position is with in available range
QDesktopWidget *desktop = QApplication::desktop();
QRect desktopRect = desktop->availableGeometry();
if(desktopRect.contains(keyEvent->globalPos())){
this->move(this->pos() + (keyEvent->globalPos() - mLastMousePosition));
mLastMousePosition = keyEvent->globalPos();
return true;
}
This is not working. Where I am doing wrong.
Pls, show me a way to acheive this.
Thanks.