The disvantage of Button Box is that we can't set the buttons properties in the Designer, we have to do that programmatically.
We copy DlgGoToCell.ui to DlgGoToCell2.ui and modify the last one, removing buttons and spacer, and putting in a Button Box.
We recompile, so qmake could create ui_DlgGoToCell2.h that we will use instead. Then we modify the DlgGoToCell class. In the include file we refer to ui_DlgGoToCell2.h instead of ui_DlgGoToCell.h, and the class DlgGoToCell would extends QDialog, as before, but Ui::DlgGoToCell2 instead of Ui::DlgGoToCell.
The code of the constructor change in this way:
DlgGoToCell::DlgGoToCell(QWidget *parent) : QDialog(parent)
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); // 1.
where->setValidator(new QRegExpValidator(regExp, this));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); // 2.
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
1. we have to disable the button programmatically, as we said before
2. the button box provides the accepted() / rejected() signals that we use for connection to accept() / reject()
We have to change also on_where_textChanged(), to refer to the button box:
I wrote this post as homework while reading "C++ GUI Programming with Qt 4, Second Edition" by Jasmin Blanchette and Mark Summerfield.