简体   繁体   English

Qt - 禁用 QDialog 的“?” 按钮

[英]Qt - Disabling QDialog's “?” button

I create an instance of QDialog and on the left of 'x' (close) button i have also '?'我创建了一个 QDialog 实例,在“x”(关闭)按钮的左侧我也有“?” button.按钮。 How I can disable that '?'我怎样才能禁用那个“?” ? ?

更改窗口标志,例如在构造函数中:

this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);

From the Qt 4.6 QDialog documentation:来自 Qt 4.6 QDialog 文档:

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

Constructs a dialog with parent 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.小部件标志f被传递给QWidget构造函数。 If, for example, you don't want a **What's This button in the title bar of the dialog**, pass Qt::WindowTitleHint | Qt::WindowSystemMenuHint例如,如果您不想要对话框标题栏中的**What's This按钮**,请传递Qt::WindowTitleHint | Qt::WindowSystemMenuHint Qt::WindowTitleHint | Qt::WindowSystemMenuHint in f . f Qt::WindowTitleHint | Qt::WindowSystemMenuHint

See also QWidget::setWindowFlags() .另见QWidget::setWindowFlags()

If you just want to disable the button, you can call setEnabled(bool) , but I doubt that's what's being asked.如果您只想禁用该按钮,您可以调用setEnabled(bool) ,但我怀疑这就是被问到的问题。

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. QDialog旨在使用QDialogButtonBox作为显示在对话框上的按钮。 You can use accessors available in QDialogButtonBox in order to disable the buttons you don't want (as well as enable others).您可以使用QDialogBu​​ttonBox中可用的访问器来禁用您不想要的按钮(以及启用其他按钮)。

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.还应该有可以检查的属性(复选框),以控制默认情况下可以访问哪些按钮。

对于 Qt 5.10 及更高版本,您可以使用应用程序范围标志 Qt::AA_DisableWindowContextHelpButton

 app.setAttribute(Qt::AA_DisableWindowContextHelpButton);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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