Skip to content
  • 0 Votes
    9 Posts
    1k Views
    Christian EhrlicherC

    Name your buttons in designer radioButton_X with X as your id, use a loop in your code to add them to QButtonGroup later on:

    QButtonGroup *bg = ... for (int i = 1; i <= maxCount; ++i) { auto button = findChild<QRadioButton*>(QString("radioButton_%1").arg(i)); if (button) { bg->addButton(button, id); } else { qWarning() << "Something went wrong"; } }

    or directly address them

    const auto buttons = { ui->radioButton_1, ui->radioButton_2, ... }; int id = 1; for (auto button : buttons) bg->addButton(button, id++);
  • 0 Votes
    2 Posts
    245 Views
    JonBJ

    @voltron
    I don't read QWizardPage::registerField() as making the widget mandatory to fill out? Only if you choose to make it compulsory.

  • 0 Votes
    3 Posts
    271 Views
    Joe JohnsonJ

    @J-Hilk It works,thanks

  • 0 Votes
    6 Posts
    2k Views
    L

    @JonB

    Hi I just tried it again, and indeed it worked without setting any other choices to false. Don't know why it didn't work before...

    switch (savedFormat) { case MyFormat::ChoiceOne: m_ui.mySavingRadioButton_choiceOne->setChecked(true); break; case MyFormat::ChoiceTwo: m_ui.mySavingRadioButton_choiceTwo->setChecked(true); break; }
  • 0 Votes
    6 Posts
    3k Views
    D

    QCheckBox inherits from QAbstractButton, which provides a hitButton method that controls which parts of the button are clickable. All you need to do is make a new subclass of QCheckBox and override hitButton so it always returns true:

    class BigHitCheckBox : public QCheckBox { bool hitButton(const QPoint & pos) const override { Q_UNUSED(pos); return true; } };

    This is much simpler than the solutions previously mentioned, and it should play well with the hovering, disabling, and tristate features of the checkbox without any extra effort.

    By the way, this makes the entire checkbox widget clickable, but it doesn't make other widgets outside the checkbox clickable. I don't think the OP needed that.

    --David

  • 0 Votes
    5 Posts
    1k Views
    mrjjM

    Hi
    Checkbox is a QAbstractButton child.
    I think QButtonGroup is the one doing the real work of "exclusive" so I wonder if its possible to
    create a child of QButtonGroup and teach it to handle new types.
    But for QGroupBox, I did not trip over anything that suggest it can use another QButtonGroup. :(

  • 0 Votes
    6 Posts
    4k Views
    p3c0P

    @CodeVisio
    For checkboxes I think you must have set Qt::ItemIsUserCheckable flag for QListWidgetItem. So there's a way to do so. But for radiobutton theres none and thus have to create the widget explicitly.

    Edit: Links