#include"appinit.h"#include<QMouseEvent>#include<QApplication>#include<QWidget>Appinit::appinit (Qobject*parent): Qobject (parent) {mousepressed=false; Qapp->installeventfilter ( This);}voidappinit::load () {}BOOLAppinit::eventfilter (Qobject *obj, Qevent *evt) {Qwidget*w = (Qwidget *) obj; if(Evt->type () = =qevent::keypress) {qkeyevent*Event= Static_cast<qkeyevent *>(EVT); if(Event->key () = =Qt::key_escape) { return true; } } if(!w->property ("Canmove"). Tobool ()) {returnqobject::eventfilter (obj, evt); } qmouseevent*Event= Static_cast<qmouseevent *>(EVT); if(Event->type () = =qevent::mousebuttonpress) { if(Event->button () = =Qt::leftbutton) {mousepressed=true; Mousepoint=Event->globalpos ()-w->POS (); return true; } } Else if(Event->type () = =qevent::mousebuttonrelease) {mousepressed=false; return true; } Else if(Event->type () = =qevent::mousemove) { if(Mousepressed && (Event->buttons () &&Qt::leftbutton)) {W->move (Event->globalpos ()-mousepoint); return true; } } returnqobject::eventfilter (obj, evt);}
The most important feature of this approach is that it does not affect the design of other class hierarchies without forcing the Qdialog to inherit from me. And doing everything in the world is possible.
By setting the filter globally, you can make all the Windows movable, rather than inheriting the specified Qdialog