1

I need to add one or several radiobuttons (depends on registered GPU Models). It looks like:

 QVBoxLayout *vLayout = new QVBoxLayout(this);
 QList<OpenCLGpuModel *> gpus = getGpus();
 foreach (OpenCLGpuModel *gpu, gpus) {
    QRadioButton *rb = new QRadioButton(gpu->getName(), this);
    rb->setChecked(gpu->isEnabled());
    vLayout->addWidget(rb);
}
setLayout(vLayout);

There is only one radio button should be selected in each moment. If I have several radio buttons the behaviour is good. But, if I have the only one it works as it a checkbox - if I click on it and it's already checked, then it'll be unchecked. How can I fix this behavior in the case of one QRadioButton?

Pete Ythong
  • 305
  • 5
  • 13
Dmitrii
  • 618
  • 2
  • 7
  • 19
  • Maybe this will set you on the right path? In HTML you would make a radio button required=true and give it a default value of true. – Sydney Y Feb 05 '20 at 06:25
  • 3
    Have a look at [QButtonGroup](https://doc.qt.io/qt-5/qbuttongroup.html#details) and specifically at [QButtonGroup::setExclusive()](https://doc.qt.io/qt-5/qbuttongroup.html#exclusive-prop). – Scheff's Cat Feb 05 '20 at 07:11
  • Yes, there is the answer! Thanks a lot! – Dmitrii Feb 05 '20 at 07:55

0 Answers0