Button groups with tab focus
From QtCentreWiki
Introduction
When using exlusive buttons, like a set of radio buttons, it is not possible to use the tab key to set the focus on the next radio button. Only the arrow keys can be used.
This might give problems in certain applications. Therefor, this example demonstrates a way to create button groups with exclusive buttons that can use the tab key to focus the next or previous radio button.
The example
A class CustomButtonGroup is created. It's base on QObject. When you want to create a new button group, use this class to add the buttons to. Example:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QGridLayout *layout = new QGridLayout; CustomButtonGroup *cBG = new CustomButtonGroup; QRadioButton *radio1 = new QRadioButton("radio 1"); QRadioButton *radio2 = new QRadioButton("radio 2"); cBG->addButton(radio1); cBG->addButton(radio2); layout->addWidget(radio1); layout->addWidget(radio2); ui->centralWidget->setLayout(layout); }
In this example, two radio buttons are created and added to a CustomButtonGroup called cBG. The CustomButtonGroup handles the selections of the radio buttons.
The CustomButtonGroup class
Download and include the following header and implementation in your project to take advantage of this class. It does not have the same features as QButtonGroup because this is only to demonstrate the technique. The implementation of the missing QButtonGroup functions is left as an exercise for the reader.

