I create an instance of QDialog and on the left of 'x' (close) button i have also '?' button. How I can disable that '?' ?
4 Answers
Change the window flags, for example in the constructor:
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
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
fare passed on to theQWidgetconstructor. If, for example, you don't want a **What's This button in the title bar of the dialog**, passQt::WindowTitleHint | Qt::WindowSystemMenuHintinf.
See also QWidget::setWindowFlags().
- 13,914
- 19
- 78
- 147
- 55,122
- 7
- 121
- 140
-
2For QDialog Qt::WindowTitleHint | Qt::WindowSystemMenuHint flags cause an abnormal behaviour. – Narek Jun 10 '10 at 06:29
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"));
findButton->setDefault(true);
moreButton = new QPushButton(tr("&More"));
moreButton->setCheckable(true);
moreButton->setAutoDefault(false);
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.
- 45,767
- 19
- 102
- 147
-
1This 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 04 '10 at 14:41
-
Oh. I think you're right -- I definitely misunderstood that one :(. – Kaleb Pederson Jun 04 '10 at 15:26
For Qt 5.10 and higher you can use application wide flag Qt::AA_DisableWindowContextHelpButton
app.setAttribute(Qt::AA_DisableWindowContextHelpButton);
- 1,364
- 17
- 33
Qt::WindowFlags flags = windowFlags(); flags &= ~Qt::WindowContextHelpButtonHint; setWindowFlags(flags);– Elias Bachaalany Oct 05 '10 at 15:17