How can I hide / delete "?" help in the Qt Dialog title bar?

I am using Qt Dialogs in one of my applications. I need to hide / remove the help button. But I can’t find where exactly I get the handle of his help button. Not sure if its specific flag in Qt window.

+61
qt qt4 qdialog
Sep 17 '08 at 9:59
source share
8 answers

By default, the Qt :: WindowContextHelpButtonHint flag is added to the dialogs. You can control this with the WindowFlags parameter in the dialog constructor.

For example, you can specify only the TitleHint and SystemMenu flags:

QDialog *d = new QDialog(0, Qt::WindowSystemMenuHint | Qt::WindowTitleHint); d->exec(); 

If you add the Qt :: WindowContextHelpButtonHint flag, you will return the help button.

In PyQt, you can:

 from PyQt4 import QtGui, QtCore app = QtGui.QApplication([]) d = QtGui.QDialog(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint) d.exec_() 

For more information on window flags, see the WindowType listing in the Qt documentation.

+51
Sep 17 '08 at 10:44
source share

Ok, I found a way to do this.

It deals with Window checkboxes. So here is the code I used:

 Qt::WindowFlags flags = windowFlags() Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint; flags = flags & (~helpFlag); setWindowFlags(flags); 

But in this case, sometimes the dialog icon appears reset. Therefore, so that the dialog icon does not change, you can add two lines.

 QIcon icon = windowIcon(); Qt::WindowFlags flags = windowFlags(); Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint; flags = flags & (~helpFlag); setWindowFlags(flags); setWindowIcon(icon); 
+28
Sep 17 '08 at 11:53
source share
 // remove question mark from the title bar setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); 
+28
Jun 19 '15 at 9:43 on
source share

I ran into this issue on Windows 7, Qt 5.2, and the flag combination that worked best for me was as follows:

Qt :: WindowTitleHint | Qt :: WindowCloseButtonHint

This gives me a working close button, but without a question mark help button. Using only Qt :: WindowTitleHint or Qt :: WindowSystemMenuHint, he got rid of the help button, but also disabled the close button.

As Michael Bishop suggested, he played with an example of window flags that led me to this combination. Thank!

+10
Feb 26 '14 at 11:07
source share

Starting with Qt 5.10, you can disable these buttons globally with a single QApplication attribute!

 QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); 
+8
Apr 18 '18 at 17:46
source share

The answers given here will work, but to answer it yourself, I recommend you run the $QTDIR/examples/widgets/windowflags . This will allow you to test all configurations of window flags and their effects. Very useful for identifying problems with white window flags.

+4
Dec 11 '08 at 2:15
source share

You can use the following default removal of question marks for all dialogs in the application:

Attach the following event filter to QApplication somewhere at the beginning of your program:

  bool eventFilter (QObject *watched, QEvent *event) override { if (event->type () == QEvent::Create) { if (watched->isWidgetType ()) { auto w = static_cast<QWidget *> (watched); w->setWindowFlags (w->windowFlags () & (~Qt::WindowContextHelpButtonHint)); } } return QObject::eventFilter (watched, event); } 
+1
Aug 29 '17 at 12:34 on
source share

I could not find the slot, but you can override the winEvent virtual function.

 #if defined(Q_WS_WIN) bool MyWizard::winEvent(MSG * msg, long * result) { switch (msg->message) { case WM_NCLBUTTONDOWN: if (msg->wParam == HTHELP) { } break; default: break; } return QWizard::winEvent(msg, result); } #endif 
0
Sep 28 '10 at 10:12
source share



All Articles