qt 移动无边框的窗体

在成员变量中添加

dragPosition 

然后重写下面面个函数


void  mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        dragPosition = event->globalPos() - frameGeometry().topLeft();
        event->accept();
    }
    if (event->button() == Qt::RightButton)
        close();//如果是右键,则关闭窗体
}

void  mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() && Qt::LeftButton)
    {
        move(event->globalPos() - dragPosition);
        event->accept();
    }
}




你可能感兴趣的:(qt)