qt在创建一个窗口时可以设置窗口的风格(默认按钮,边框等),本文就是对常用的一些窗口的样式枚举做一个记录。
设置方法
this->setWindowFlags()函数设置窗口样式,内部为WindowType的枚举的与集合。
Dialog::Dialog(QWidget *parent) :QDialog(parent),ui(new Ui::Dialog)
{ui->setupUi(this);this->setWindowModality(Qt::WindowModal);//设置模态this->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);//设置窗口样式
}
类型介绍
上面这一部分是窗口的整体风格,设置窗口显示位置,边框,类型,选一个就好
Widget = 0x00000000,Window = 0x00000001,Dialog = 0x00000002 | Window,Sheet = 0x00000004 | Window,Drawer = Sheet | Dialog,Popup = 0x00000008 | Window,Tool = Popup | Dialog,ToolTip = Popup | Sheet,SplashScreen = ToolTip | Dialog,Desktop = 0x00000010 | Window,SubWindow = 0x00000012,ForeignWindow = 0x00000020 | Window,CoverWindow = 0x00000040 | Window,
下面这一部分是在一个按钮组合,可以多选,根据需求组合出自己想要的按钮选项
MSWindowsFixedSizeDialogHint = 0x00000100,MSWindowsOwnDC = 0x00000200,BypassWindowManagerHint = 0x00000400,X11BypassWindowManagerHint = BypassWindowManagerHint,FramelessWindowHint = 0x00000800,WindowTitleHint = 0x00001000,WindowSystemMenuHint = 0x00002000,WindowMinimizeButtonHint = 0x00004000,WindowMaximizeButtonHint = 0x00008000,WindowMinMaxButtonsHint = WindowMinimizeButtonHint | WindowMaximizeButtonHint,WindowContextHelpButtonHint = 0x00010000,WindowShadeButtonHint = 0x00020000,WindowStaysOnTopHint = 0x00040000,WindowTransparentForInput = 0x00080000,WindowOverridesSystemGestures = 0x00100000,WindowDoesNotAcceptFocus = 0x00200000,MaximizeUsingFullscreenGeometryHint = 0x00400000,CustomizeWindowHint = 0x02000000,WindowStaysOnBottomHint = 0x04000000,WindowCloseButtonHint = 0x08000000,MacWindowToolBarButtonHint = 0x10000000,BypassGraphicsProxyWidget = 0x20000000,NoDropShadowWindowHint = 0x40000000,WindowFullscreenButtonHint = 0x80000000
几种典型样式
Qt::Widget
this->setWindowFlags(Qt::Widget);
这个设置完毕后,对应的窗口就会变成一个widegt,本身没有边框和背景色。内部的空间会直接排列在父窗口上。
![在这里插入图片描述](https://img-blog.csdnimg.cn/717a3171dfea4095b363a10c91db7d12.png
Qt::Window
this->setWindowFlags(Qt::Window);