[英]Remove WindowSystemMenuHint from QDialog in Qt
我想从Qt的QDialog
标题栏中删除系统菜单和上下文菜单。 我已经在下面编写了代码,但是它不起作用。
Qt::WindowFlags flags = windowFlags();
Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint;
flags = flags & (~helpFlag);
Qt::WindowFlags systemMenuFlag = Qt::WindowSystemMenuHint;
flags = flags & (~systemMenuFlag);
setWindowFlags(flags);
当我打印windowFlags
我得到的输出仍然是WindowSystemMenuHint
。
Qutout :: QFlags(0x1|0x2|0x1000|0x2000|0x8000000).
如何删除0x2000
即WindowSystemMenuHint
?
从Qt文档
CustomizeWindowHint
标志用于启用窗口控件的自定义。 必须设置此标志以允许WindowSystemMenuHint
WindowTitleHint
,WindowSystemMenuHint
,WindowMinimizeButtonHint
,WindowMaximizeButtonHint
和WindowCloseButtonHint
标志。
所以试试这个:
Qt::WindowFlags flags = windowFlags();
flags |= Qt::CustomizeWindowHint;
flags &= ~Qt::WindowContextHelpButtonHint;
flags &= ~Qt::WindowSystemMenuHint;
setWindowFlags(flags);
Qt 4.8更新
浏览Qt源 ,可以看到当Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint
任何一个被恢复时,系统菜单提示已还原Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint
Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint
Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint
已设置。
所以这样做:
Qt::WindowFlags flags = windowFlags();
flags |= Qt::CustomizeWindowHint;
flags &= ~Qt::WindowContextHelpButtonHint;
flags &= ~Qt::WindowSystemMenuHint;
flags &= ~Qt::WindowMinMaxButtonsHint;
flags &= ~Qt::WindowCloseButtonHint;
setWindowFlags(flags);
但是您将不再有关闭按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.