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;
}