class MainWidget : public QWidget
{
Q_OBJECT
QPoint m_point; //点击的点
};
void MainWidget::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
{
QPoint point = this->frameGeometry().topLeft();
QRectF rectF = this->frameGeometry();
m_point = event->globalPos() - this->frameGeometry().topLeft();
qDebug() << "rectF:" << rectF;
qDebug() << "point:" << point;
qDebug() << "globalPos:" << event->globalPos();
}
}
void MainWidget::mouseMoveEvent(QMouseEvent * event)
{
if (event->buttons() & Qt::LeftButton)
{
move(event->globalPos() - m_point);
}
}