1.Qt在windows下变成,标题栏归系统管理器管理。想要自定义就只能把原来的隐藏掉,然后自己添加组件,自己做;
2.首先设置属性,隐藏掉原来的标题栏:
/* 标题栏样式 */
this->setWindowFlags(Qt::FramelessWindowHint |
Qt::WindowSystemMenuHint |
Qt::WindowMinMaxButtonsHint);
3.重写鼠标的三个事件,分别是:
/* custom title bar */
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
4.代码如下:
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if( event->button() == Qt::LeftButton &&
ui->frame_title_bar->frameRect().contains(event->globalPos() - this->frameGeometry().topLeft())){
m_Press &