简体   繁体   English

Qt中同一标题栏中的最小化按钮和上下文帮助按钮

[英]Minimize button and context help button in the same title bar in Qt

To make a help button in the title bar in a Qt window of the type QWidget, I do like this: 要在QWidget类型的Qt窗口的标题栏中创建一个帮助按钮,我喜欢这样:

myWindow->setWindowFlags(Qt::WindowContextHelpButtonHint);

This works fine. 这很好。

To make a minimize button in the title bar in the same kind of window, I do like this: 要在相同类型的窗口的标题栏中创建一个最小化按钮,我喜欢这样:

myWindow->setWindowFlags(Qt::WindowMinimizeButtonHint);

This also works fine. 这也很好。

What I want to do is to have both a help button and a minimize button in the title bar of same window. 我想做的是在同一窗口的标题栏中同时有一个帮助按钮和一个最小化按钮。 For that, I tried to combine the flags: 为此,我尝试结合这些标志:

myWindow->setWindowFlags(Qt::WindowContextHelpButtonHint | Qt::WindowMinimizeButtonHint);

This only shows the minimize button, not the help button (at least in Windows). 这仅显示最小化按钮,而不显示帮助按钮(至少在Windows中是这样)。 How do I show both buttons in the same title bar? 如何在同一标题栏中显示两个按钮?

Unfortunately, this is impossible on windows. 不幸的是,这在Windows上是不可能的。 Here is why: 原因如下:

  • Qt::WindowMinimizeButtonHint is implemented by adding WS_MINIMIZEBOX window style, see here . Qt::WindowMinimizeButtonHint通过添加WS_MINIMIZEBOX窗口样式来实现,请参见此处
  • Qt::WindowContextHelpButtonHint is implemented by adding WS_EX_CONTEXTHELP extended window style, see here . Qt::WindowContextHelpButtonHint通过添加WS_EX_CONTEXTHELP扩展窗口样式来实现,请参见此处

From the reference for WS_EX_CONTEXTHELP : WS_EX_CONTEXTHELP的参考中:

WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles. WS_EX_CONTEXTHELP不能与WS_MAXIMIZEBOXWS_MINIMIZEBOX样式一起使用。

So, you can never have a window with the minimize button [ - ] and the context help button [ ? 因此,永远不会有带有最小化按钮[-]和上下文帮助按钮[? ] on windows. ]在Windows上。

If you really want to do so, you may have to use a frameless window, and provide your own custom frames. 如果确实要这样做,则可能必须使用无框架窗口,并提供自己的自定义框架。

Note: This answer is about windows platform only. 注意:此答案仅与Windows平台有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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