// Create a QDialogButtonBox with Ok and Cancel buttons QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); // Connect the signals of the QDialogButtonBox and QDialog connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); // Add the QDialogButtonBox to a QDialog window QDialog *dialog = new QDialog; QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(buttonBox); dialog->setLayout(layout); dialog->exec();
// Create a QDialogButtonBox with Ok, Cancel, and Apply buttons QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); // Change the order of buttons in the QDialogButtonBox buttonBox->button(QDialogButtonBox::Apply)->setText(tr("Save")); buttonBox->button(QDialogButtonBox::Apply)->setToolTip(tr("Save changes")); buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); // Add the QDialogButtonBox to a layout or window
// Create a custom button QPushButton *button = new QPushButton(tr("Custom Button")); // Add the button to the QDialogButtonBox QDialogButtonBox *buttonBox = new QDialogButtonBox; buttonBox->addButton(button, QDialogButtonBox::ActionRole); // Connect the signal of the custom button connect(button, SIGNAL(clicked()), this, SLOT(onCustomButtonClicked())); // Add the QDialogButtonBox to a layout or windowThese examples use the Qt library.