QRadioButton



  • Hello, is there any way to show two sets of QRadioButton in the same place? I did a logic where the click of a QPushButton one QRadioButton group appears (setVisible (True)) and the other disappears (setVisible (False)) and click another button the opposite occurs, but I'd like to show these two sets in the same place when one does not appear the other appear and vice-versa, is it possible? I did the screen using Qt Design and programming the logic later.


  • Lifetime Qt Champion

    Hi,

    You can use a QStackedWidget for that. Create two widgets, each containing a set of your buttons and just change the QStrackedWidget index to match the series of QRadioButton you want to use.

    What do you mean by "use in another situation" ? Can you explain your use case ?



  • Look at the suggestion from @SGaist, I think it will work the best.

    An alternative is to use a layout (QVBoxLayout or QHBoxLayout). If the widget is hidden in the layout it will do what you want. I use that approach on the settings page of my SpellChecker Plugin.



  • Small example that shows how this can be done.

    QWidget* widget = new QWidget(nullptr);
    QVBoxLayout* layout = new QVBoxLayout(widget);
    QLabel* label1 = new QLabel("Label One");
    QLabel* label2 = new QLabel("Label Two");
    QPushButton* button = new QPushButton("Push me!!!");
    
    layout->addWidget(label1);
    layout->addWidget(label2);
    layout->addWidget(button);
    
    label2->setHidden(true);
    connect(button, &QPushButton::clicked, [label1, label2](){
        label1->setVisible(!label1->isVisible());
        label2->setVisible(!label2->isVisible());
    });
    
    widget->show();
    

    I know this is not using designer, but you can do the same with designer.

    [Edit] Also this uses QLabels but the same can be done using any other widgets



  • @SGaist Thanks, I used QStackedWidget and I made pages with QRadioButton and the result was exactly what I wanted. And the "use in another situation" refers to I want to save in my program which was the user's choice in QRadioButton, because on the next page of my program I will show a picture related to that choice. In fact, there are any suggestions on how I can do this?


  • Lifetime Qt Champion

    Sounds like a QWizard, no ?



  • @SGaist Yes.


  • Lifetime Qt Champion

    Then you can either take some ideas of QWizard's implementation or use it directly


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.