没有窗口图标的 Qt 对话框(系统菜单)
有没有办法创建一个窗口(例如QDialog),左上角没有窗口图标? 我尝试过使用透明图标,但它在那里留下了空白。
编辑: richardwb 下面的解决方案删除了系统菜单,但也删除了最小化/最大化/关闭(标题按钮)。 目前这可能可行,但希望有一个保留字幕按钮的解决方案。
Is there a way to create a window (such as a QDialog
), without a window icon on the top-left corner? I have tried using a transparent icon but it leaves a blank space there.
Edit: richardwb's solution below removes the system menu, but also removes Minimize/Maximize/Close (caption buttons) as well. This might do for now, but hopefully there is a solution that preserves the captions buttons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您根本不需要任何标题按钮,您可以通过设置一些 窗口标志提示:
Qt 的演示应用程序有一个示例应用程序,如果您想查看的话,可以让您试验这些标志(Qt Demo->Widgets->Window Flags)不同的组合会做什么。
另一方面,如果您想要任何最小化/最大化/关闭按钮,您会注意到 Qt 强制显示系统菜单和窗口图标。 我认为这是 Qt 对平台的概括,因为很容易找到带有关闭按钮但没有系统菜单和窗口图标的本机 Windows 对话框的示例。
在这种情况下,您将需要一些 Windows 特定代码,类似于此(未经测试):
编辑:正如 swongu 所评论的,这仅在您想要没有系统菜单的关闭按钮时才有效。 如果您想要最小化/最大化按钮但没有系统菜单,那么您就不走运了。
If you don't need any caption buttons at all, you can achieve this by setting some window flag hints:
Qt's Demo application has a sample application that lets you experiment with these flags (Qt Demo->Widgets->Window Flags) if you want to see what different combinations do.
On the other hand, if you want any of the Minimize/Maximize/Close buttons, you will notice Qt forces the system menu and window icon to show up. I think this is Qt generalizing the platforms a bit, as it's very easy to find examples of native Windows dialogs with a Close button but without the system menu and window icon.
In that case, you will need some Windows specific code, similar to this (untested):
Edit: As commented by swongu, this only works if you want to have a close button without a system menu. If you want a minimize/maximize button but no system menu, you're out of luck.
受到 @richardwb 答案的启发,我执行了以下操作(Qt 5.12),以免影响 QDialog 的现有窗口标志:
Inspired by the answer from @richardwb , I did the following (Qt 5.12), to not affect the existing window flags for my QDialog: