Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved QRadioButton

    General and Desktop
    3
    8
    1721
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Pedro_Monteiro last edited by Pedro_Monteiro

      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.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        P 1 Reply Last reply Reply Quote 0
        • TheBadger
          TheBadger last edited by

          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.


          Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

          1 Reply Last reply Reply Quote 0
          • TheBadger
            TheBadger last edited by TheBadger

            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


            Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

            1 Reply Last reply Reply Quote 0
            • P
              Pedro_Monteiro @SGaist last edited by

              @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?

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Sounds like a QWizard, no ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                P 1 Reply Last reply Reply Quote 0
                • P
                  Pedro_Monteiro @SGaist last edited by

                  @SGaist Yes.

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

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

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post