1. widget重新三个函数
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
2. 实现如下
void KMainWidget::mousePressEvent(QMouseEvent* event)
{
Q_UNUSED(event);
m_isPress = true;
m_startPos = event->globalPos() - this->frameGeometry().topLeft();
}
void KMainWidget::mouseMoveEvent(QMouseEvent* event)
{
if (m_isPress)
{
move(this->mapToGlobal(event->pos() - m_startPos));
}
}
void KMainWidget::mouseReleaseEvent(QMouseEvent* event)
{
m_isPress = false;
}
标签:Qt,自定义,拖动,void,QMouseEvent,isPress,KMainWidget,override,event
From: https://www.cnblogs.com/wanghongyang/p/16730097.html