(1_255)Qt拖动没有标题栏的窗体

在main中:

w.setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏;

在*.h中:

QPoint windowPos,mousePos,dPos;

在*.cpp:

void yourwindow::mousePressEvent(QMouseEvent *event)

{                                                                                                          

     this->windowPos = this->pos();  // pos()是相对于窗口的,以窗口左上角为原点(去除边框)。即pos()给出的是一个相对位置坐标。而globalPos(),给出的是一个绝对坐标。

     this->mousePos = event->globalPos();  //    globalpos()给出的坐标信息是相对于桌面的,即以桌面左上角为原点

    this->dPos = mousePos - windowPos;  

}  


void yourwindow::mouseMoveEvent(QMouseEvent *event)

{  

      this->move(event->globalPos() - this->dPos);  

}


你可能感兴趣的:(信息,标题栏)