/// <summary> /// 获得鼠标按下事件 /// </summary> /// <param name=""></param> void mousePressEvent(QMouseEvent*) override; /// <summary> /// 获得鼠标移动事件 /// </summary> /// <param name=""></param> void mouseMoveEvent(QMouseEvent*) override;
//用法
void DigiClock::mousePressEvent(QMouseEvent* event) { if (event->button()==Qt::LeftButton) {标签:dragPosition,qt,mousePressEvent,void,QMouseEvent,窗体,移动,event,Qt From: https://www.cnblogs.com/cwb8023/p/17275434.html
//QPoint dragPosition
//QWidget::frameGeometry()
dragPosition = event->globalPos() - frameGeometry().topLeft(); event->accept(); }
if (event->button()==Qt::RightButton) { close(); }
}
void DigiClock::mouseMoveEvent(QMouseEvent* event)
{
if (event->buttons()&Qt::LeftButton)
{ move(event->globalPos() - dragPosition); event->accept(); }
}