//上面缺号头文件,自行添加哦 class DragtidgetFilter :public Qobject{ public: DragWidgetFilter(QObject* parent) :Q0bject(parent){} //重写事件 bool eventFilter(Qobject* object,QEvent* event) { auto n= dynanic_cast<QWidget*>( object); if(!w) return false; if(event→type()==QEvent::MouseButtonPress) { auto ev= dynamic_cast<QMouseEvent*>(event); if(!ev) return false; pos=ev→pos(); } else if(event→type()==QEvent::MouseMove) { auto ev= dynamic_cast<QMouseEvent*>(event); if(!ev) return false; if(ev→buttons()&Qt::MouseButton::LeftButton) w→move(ev→globalPosition().toPoint()-pos); } } return qobject::eventFilter(object, event);} private: QPoint pos; };
标签:窗口,QT,拖动,auto,pos,return,false,ev,event From: https://www.cnblogs.com/hech/p/18411604