Qt - Disabling QDialog's “?” button

前端 未结 4 702
旧巷少年郎
旧巷少年郎 2021-02-07 01:15

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

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-07 01:49

    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.

提交回复
热议问题