Search code examples
c++qtqt4designer

How do I change properties of buttons within button boxes in Qt Designer?


I have been searching online to no avail. Does anyone know how to access a button in a button box (created using the "Dialog with Buttons Right" template)?


Solution

  • In Designer, select the OK or Cancel button. Then open the property editor and scroll down to the QDialogButtonBox section. You can then expand the standardButtons item to see the various buttons that are available. Other properties, such as the centerButtons property, are also available.

    However, designer gives you very little control over the button box.

    In code, you can do many other things, such as change the text that appears on the "standard buttons." From the documentation:

    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);
    

    As long as you give the button box a name in designer, you can set these properties in code.