Qt——无边框窗口移动
实现无边框传统的方法就是实现鼠标按下、移动、释放事件
声明:
bool mMousePressed; QPoint mRelativeSrcPos; //全局位置
实现:
void CDropShadowWidget::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { mMousePressed = true; mRelativeSrcPos = event->globalPos() - pos(); } } void CDropShadowWidget::mouseReleaseEvent(QMouseEvent *event) { mMousePressed = false; } void CDropShadowWidget::mouseMoveEvent(QMouseEvent *event) { if(mMousePressed) { move(event->globalPos() - mRelativeSrcPos); //当前位置减去相对的原点位置得到的是移动距离 } }