繁体   English   中英

从Qt中的QDialog删除WindowSystemMenuHint

[英]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).

如何删除0x2000WindowSystemMenuHint

Qt文档

CustomizeWindowHint标志用于启用窗口控件的自定义。 必须设置此标志以允许WindowSystemMenuHint WindowTitleHintWindowSystemMenuHintWindowMinimizeButtonHintWindowMaximizeButtonHintWindowCloseButtonHint标志。

所以试试这个:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM