Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QRadioButton
Forum Updated to NodeBB v4.3 + New Features

QRadioButton

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 2.1k Views 3 Watching
  • 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 Offline
    P Offline
    Pedro_Monteiro
    wrote on last edited by Pedro_Monteiro
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • TheBadgerT Offline
        TheBadgerT Offline
        TheBadger
        wrote on last edited by
        #3

        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
        0
        • TheBadgerT Offline
          TheBadgerT Offline
          TheBadger
          wrote on last edited by TheBadger
          #4

          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
          0
          • SGaistS SGaist

            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 ?

            P Offline
            P Offline
            Pedro_Monteiro
            wrote on last edited by
            #5

            @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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0
              • SGaistS SGaist

                Sounds like a QWizard, no ?

                P Offline
                P Offline
                Pedro_Monteiro
                wrote on last edited by
                #7

                @SGaist Yes.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved