After setting the QT design window to a borderless form, the window cannot be moved. I found some materials on the Internet, picked one suitable for myself, and now share it.
1. Define a public member variable QPoint dragPosition in wight.h;
2. Rewrite mouse down events and mouse movement events
Mouse down event
void Widget::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
dragPosition = event->globalPos()-frameGeometry().topLeft();
// globalPos () gets the relative path of the root window, frameGeometry (). topLeft () gets the position of the upper left corner of the main window
event-> accept (); // Mouse event is received by the system
}
}
Mouse click event
void Widget::mouseMoveEvent(QMouseEvent *event)
{
this->move(event->globalPos()-dragPosition);
event->accept();
}Ok, it ’s so simple, right?
[Reference] http://www.xuebuyuan.com/1899289.html