qt实现窗口拖动

void DialogLogin::mousePressEvent(QMouseEvent *event)
{
// if (event->button() == Qt::LeftButton)
// {
// dragPos = event->globalPos() - frameGeometry().topLeft();
// event->accept();
// }
// else if (event->button() == Qt::RightButton)
// {
// this->hide();
// event->accept();
// }
// if (event->button() == Qt::LeftButton) {
// dragPos = event->globalPos() - frameGeometry().topLeft();
// if(frame->isHidden())
// frame->show();
// else
// frame->hide();
// event->accept();
// }
if (event->button() == Qt::LeftButton) {
dragPos = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}

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

}

void DialogLogin::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
setWindowOpacity(1);
}
event->accept();
}

:o:o:o:o:o:o:o:o:o

:7_138::7_139::7_142: