Take the 2-minute tour ×

I create an instance of QDialog and on the left of 'x' (close) button i have also '?' button. How I can disable that '?' ?

share|improve this question
add comment

3 Answers

up vote 19 down vote accepted

Change the window flags, for example in the constructor:

this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
share|improve this answer
Thanks, this is what I need. –  Narek Jun 10 '10 at 7:49
Trying to call setWindowFlags() directly did not work because the '~' was not applied. Another solution involves using the &= operator: <pre> Qt::WindowFlags flags = windowFlags(); flags &= ~Qt::WindowContextHelpButtonHint; setWindowFlags(flags); </pre> –  Elias Bachaalany Oct 5 '10 at 15:17
Actually we had the opposite problem, our dialog didn't have Help button. This answer helped us look for the problem. Thanks –  Liz Feb 16 '11 at 21:17
And by the way in PySide: self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) Does the tilde say to remove that flag? –  gseattle Jul 12 '12 at 0:08
Tilde is a bitwise complement operator that flips every bit (0->1, 1->0). & is a bitwise AND operator. When the original bits and flipped flag bits and ANDed, the flag is removed. –  Roku Jul 12 '12 at 6:48
add comment

From the Qt 4.6 QDialog documentation:

QDialog::QDialog ( QWidget * parent = 0, Qt::WindowFlags f = 0 )

Constructs a dialog with parent parent.

A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent. It will also share the parent's taskbar entry.

The widget flags f are passed on to the QWidget constructor. If, for example, you don't want a What's This button in the title bar of the dialog, pass Qt::WindowTitleHint | Qt::WindowSystemMenuHint in f.

See also QWidget::setWindowFlags().


share|improve this answer
For QDialog Qt::WindowTitleHint | Qt::WindowSystemMenuHint flags cause an abnormal behaviour. –  Narek Jun 10 '10 at 6:29
add comment

If you just want to disable the button, you can call setEnabled(bool), but I doubt that's what's being asked.

If you want to remove that button, see below:

QDialog is intended to use a QDialogButtonBox as the buttons that show up on the dialog. You can use accessors available in QDialogButtonBox in order to disable the buttons you don't want (as well as enable others).

For example (from the documentation linked to above):

findButton = new QPushButton(tr("&Find"));

moreButton = new QPushButton(tr("&More"));

buttonBox = new QDialogButtonBox(Qt::Vertical);
buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);

If you're not aware of the button box, I'd guess that designer automatically added it for you and it should have a name that makes it accessible. There should also be properties (checkboxes) that you can check in order to control which buttons are accessible by default.

share|improve this answer
This is a well-written answer, but I think he was referring to buttons in the title bar for the dialog (window decorations). –  Caleb Huitt - cjhuitt Jun 4 '10 at 14:41
Oh. I think you're right -- I definitely misunderstood that one :(. –  Kaleb Pederson Jun 4 '10 at 15:26
add comment

Your Answer


