简体   繁体   中英

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:

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). How do I show both buttons in the same title bar?

Unfortunately, this is impossible on windows. Here is why:

  • Qt::WindowMinimizeButtonHint is implemented by adding WS_MINIMIZEBOX window style, see here .
  • Qt::WindowContextHelpButtonHint is implemented by adding WS_EX_CONTEXTHELP extended window style, see here .

From the reference for WS_EX_CONTEXTHELP :

WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles.

So, you can never have a window with the minimize button [ - ] and the context help button [ ? ] on 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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