How can I hide/delete the "?" help button on the "title bar" of a Qt Dialog?

Solution 1:

// remove question mark from the title bar
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

Solution 2:

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

For instance you can specify only the TitleHint and SystemMenu flags by doing:

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

If you add the Qt::WindowContextHelpButtonHint flag you will get the help button back.

In PyQt you can do:

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

More details on window flags can be found on the WindowType enum in the Qt documentation.

Solution 3:

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

QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);

Solution 4:

Ok , I found a way to do this.

It does deal with the Window flags. So here is the code i used:

Qt::WindowFlags flags = windowFlags()

Qt::WindowFlags helpFlag =
Qt::WindowContextHelpButtonHint;

flags = flags & (~helpFlag);   
setWindowFlags(flags);

But by doing this sometimes the icon of the dialog gets reset. So to make sure the icon of the dialog 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);