void a::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton && event->pos().y()<(this->height()-mainWidget->height()))
{
m_dragging=true;
m_dragStarPos=event->pos();
}
}
void a::mouseMoveEvent(QMouseEvent *event)
{
if(m_dragging==true)
{
this->move(event->globalPos()-m_dragStarPos);
}
}
void a::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
m_dragging=false;
}
}
头文件
private:
bool m_dragging=false;
QPoint m_dragStarPos;
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
标签:mouseReleaseEvent,dragStarPos,窗口,qt,拖动,void,QMouseEvent,dragging,event
From: https://www.cnblogs.com/donghao99/p/18203963