Qt 拖动窗口

protected:

void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);

void IcCardDialog::mousePressEvent(QMouseEvent *event)
{

if( (event->button() == Qt::LeftButton) ){
    mouse_press = true;
    mousePoint = event->globalPos() - this->pos();

// event->accept();
}
}
void IcCardDialog::mouseMoveEvent(QMouseEvent *event)
{

// if(event->buttons() == Qt::LeftButton){ //如果这里写这行代码,拖动会有点问题
if(mouse_press && (mousePoint!=QPoint())){
move(event->globalPos() - mousePoint);
// event->accept();
}
}
void IcCardDialog::mouseReleaseEvent(QMouseEvent *event)
{
mouse_press = false;
mousePoint = QPoint();
}

上一篇:C++ 鼠标点击的获取


下一篇:Python获得女友聊天记录,一招解决疑神疑鬼