Qt取消窗口边框,并将窗口居中显示

目录

  • 取消窗口边框
  • 窗口居中显示

取消窗口边框

取消掉窗口边框,不能移动和放大、缩小窗口

this->setWindowFlags(Qt::FramelessWindowHint);

下面看官方解释:

Qt::FramelessWindowHint: Produces a borderless window. The user cannot move or resize a borderless window via the window system. On X11, the result of the flag is dependent on the window manager and its ability to understand Motif and/or NETWM hints. Most existing modern window managers can handle this.

窗口居中显示

1、添加头文件

#include 

2、需要居中窗口的构造函数中添加

QDesktopWidget *desktop = QApplication::desktop();
move((desktop->width()-this->width())/2,(desktop->height()-this->height())/2);

图解:
Qt取消窗口边框,并将窗口居中显示_第1张图片

你可能感兴趣的:(Qt)