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. Layout, widgets not inside ???
Forum Updated to NodeBB v4.3 + New Features

Layout, widgets not inside ???

Scheduled Pinned Locked Moved Unsolved General and Desktop
87 Posts 9 Posters 9.9k Views 4 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.
  • J JKSH
    22 Oct 2021, 04:52

    @SPlatten Here's my suggestion:

    1. Copy the working code from Qt Designer into a small test project. Build it and run it -- make sure the resulting GUI looks correct.
    2. Gradually modify the working code to become more and more like your own custom code. Rebuild and re-run it after each small modification -- make sure the resulting GUI still looks correct at each step.
    3. As soon as the GUI stops looking correct, investigate your latest modifications.

    That will help you pinpoint exactly what's causing the GUI to look "not right".

    S Offline
    S Offline
    SPlatten
    wrote on 23 Oct 2021, 06:56 last edited by
    #68

    @JKSH , I will try what you suggest, single stepping through my existing code this is what is done, using this XML:

    <groupbox id="enSEX" eol="true" align="left" layout="vertical" title="Radios"
    		  dbfield="vcSex" properties="QGroupBox { border-radius: 8px; background-color:#ff0000; }">
    	<radiobutton id="rdoM" text="Male" default="true" position="0,0"/>
    	<radiobutton id="rdoF" text="Female" position="1,0"/>
    </groupbox>
    

    A node is created with a widget which I name with setObjectName to groupbox, id: enSEX, this node has a layout attribute so a layout QVBoxLayout is created:

    ...
                } else if ( strLayout.compare(clsXMLnode::mscszLayoutVertical) == 0 ) {
                    mpobjLayout = new QVBoxLayout(mpobjWidget);
                    strName = "QVBoxLayout";
                }
                if ( strName.isEmpty() != true ) {
                    mpobjLayout->setObjectName(strName + QString(", id: %1")
                                    .arg(strGetAttribute(clsXMLnode::mscszAttrID)));
                }
    

    The first radio button is created as a child of QGroupBox, it has the object name radiobutton, id: rdoM, so far the debugger shows:
    Screenshot 2021-10-23 at 07.50.43.png
    Then I carry on to the next radio button which has the object name radiobutton, id: rdoF, the result in the debugger doesn't look correct anymore and now shows:
    Screenshot 2021-10-23 at 07.53.28.png
    Where has radiobutton, id: rdoM gone and the output is still wrong:
    Screenshot 2021-10-23 at 07.55.19.png
    The radio buttons work correctly, the layout has the title and correct style but why or why do the radio buttons appear outside of the layout?

    Kind Regards,
    Sy

    J 1 Reply Last reply 23 Oct 2021, 07:53
    0
    • S SPlatten
      23 Oct 2021, 06:56

      @JKSH , I will try what you suggest, single stepping through my existing code this is what is done, using this XML:

      <groupbox id="enSEX" eol="true" align="left" layout="vertical" title="Radios"
      		  dbfield="vcSex" properties="QGroupBox { border-radius: 8px; background-color:#ff0000; }">
      	<radiobutton id="rdoM" text="Male" default="true" position="0,0"/>
      	<radiobutton id="rdoF" text="Female" position="1,0"/>
      </groupbox>
      

      A node is created with a widget which I name with setObjectName to groupbox, id: enSEX, this node has a layout attribute so a layout QVBoxLayout is created:

      ...
                  } else if ( strLayout.compare(clsXMLnode::mscszLayoutVertical) == 0 ) {
                      mpobjLayout = new QVBoxLayout(mpobjWidget);
                      strName = "QVBoxLayout";
                  }
                  if ( strName.isEmpty() != true ) {
                      mpobjLayout->setObjectName(strName + QString(", id: %1")
                                      .arg(strGetAttribute(clsXMLnode::mscszAttrID)));
                  }
      

      The first radio button is created as a child of QGroupBox, it has the object name radiobutton, id: rdoM, so far the debugger shows:
      Screenshot 2021-10-23 at 07.50.43.png
      Then I carry on to the next radio button which has the object name radiobutton, id: rdoF, the result in the debugger doesn't look correct anymore and now shows:
      Screenshot 2021-10-23 at 07.53.28.png
      Where has radiobutton, id: rdoM gone and the output is still wrong:
      Screenshot 2021-10-23 at 07.55.19.png
      The radio buttons work correctly, the layout has the title and correct style but why or why do the radio buttons appear outside of the layout?

      J Offline
      J Offline
      JonB
      wrote on 23 Oct 2021, 07:53 last edited by JonB
      #69

      @SPlatten
      I am just jumping in here. I have not read & digested all previous posts here, and I don't intend to, but just a comment.

      Will take a good look, because the verticalLayoutWidget looks like its added by Qt Creator and is obviously required, and thats something thats missing in my code.

      I did not do anything to add the mysterious verticalLayoutWidget which was added by Qt Creator. I am saying this works and its only because Qt Creator is doing something else instead of adding a QGroupBox, QVBoxLayout and child widgets.

      I do not think you should have any such "verticalLayoutWidget" widget.

      Dragged Vertical Layout from Layouts palette and dropped onto Group Box

      This is not the right thing to do. The correct actions in Designer should be:

      1. Drag QGroupBox onto canvas.
      2. Next drag one QRadioButton onto the QGroupBox widget.
      3. Now --- and only after step #2 can this be done --- right click on the QGroupBox. From the bottom item which reads Lay out pick Lay Out Vertically.

      This is the (irritating) way Designer requires you to place a layout on a widget (took me ages to appreciate this when I first started using Designer). It does not allow you to do so till after the container has had at least one child widget added. This creates a different structure from your "Dragged Vertical Layout from Layouts palette", which you should not do. (Indeed, if you do your way in Designer and look you will see the group box has a "no entry" sign indicating this is incorrect, it is missing its own layout.)

      To address whatever your issue is. By now you have spent a large amount of time asking about your existing, complex code. Instead take the example from https://doc.qt.io/qt-5/qgroupbox.html#details. Get rid of all your code. Does that draw your widgets/group box/layout correctly? Assuming it does, build back from there to your real code, or down from your code to the working code. (For example, get rid of all your parsing code, just test as you incrementally add hard-coded group boxes, layouts and radiobuttons to mirror what you would like to be doing when it's actually reading your XML file.)

      S 2 Replies Last reply 23 Oct 2021, 08:37
      1
      • J JonB
        23 Oct 2021, 07:53

        @SPlatten
        I am just jumping in here. I have not read & digested all previous posts here, and I don't intend to, but just a comment.

        Will take a good look, because the verticalLayoutWidget looks like its added by Qt Creator and is obviously required, and thats something thats missing in my code.

        I did not do anything to add the mysterious verticalLayoutWidget which was added by Qt Creator. I am saying this works and its only because Qt Creator is doing something else instead of adding a QGroupBox, QVBoxLayout and child widgets.

        I do not think you should have any such "verticalLayoutWidget" widget.

        Dragged Vertical Layout from Layouts palette and dropped onto Group Box

        This is not the right thing to do. The correct actions in Designer should be:

        1. Drag QGroupBox onto canvas.
        2. Next drag one QRadioButton onto the QGroupBox widget.
        3. Now --- and only after step #2 can this be done --- right click on the QGroupBox. From the bottom item which reads Lay out pick Lay Out Vertically.

        This is the (irritating) way Designer requires you to place a layout on a widget (took me ages to appreciate this when I first started using Designer). It does not allow you to do so till after the container has had at least one child widget added. This creates a different structure from your "Dragged Vertical Layout from Layouts palette", which you should not do. (Indeed, if you do your way in Designer and look you will see the group box has a "no entry" sign indicating this is incorrect, it is missing its own layout.)

        To address whatever your issue is. By now you have spent a large amount of time asking about your existing, complex code. Instead take the example from https://doc.qt.io/qt-5/qgroupbox.html#details. Get rid of all your code. Does that draw your widgets/group box/layout correctly? Assuming it does, build back from there to your real code, or down from your code to the working code. (For example, get rid of all your parsing code, just test as you incrementally add hard-coded group boxes, layouts and radiobuttons to mirror what you would like to be doing when it's actually reading your XML file.)

        S Offline
        S Offline
        SPlatten
        wrote on 23 Oct 2021, 08:37 last edited by
        #70

        @JonB , thank you, I will read, digest and git it a go.

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • J JonB
          23 Oct 2021, 07:53

          @SPlatten
          I am just jumping in here. I have not read & digested all previous posts here, and I don't intend to, but just a comment.

          Will take a good look, because the verticalLayoutWidget looks like its added by Qt Creator and is obviously required, and thats something thats missing in my code.

          I did not do anything to add the mysterious verticalLayoutWidget which was added by Qt Creator. I am saying this works and its only because Qt Creator is doing something else instead of adding a QGroupBox, QVBoxLayout and child widgets.

          I do not think you should have any such "verticalLayoutWidget" widget.

          Dragged Vertical Layout from Layouts palette and dropped onto Group Box

          This is not the right thing to do. The correct actions in Designer should be:

          1. Drag QGroupBox onto canvas.
          2. Next drag one QRadioButton onto the QGroupBox widget.
          3. Now --- and only after step #2 can this be done --- right click on the QGroupBox. From the bottom item which reads Lay out pick Lay Out Vertically.

          This is the (irritating) way Designer requires you to place a layout on a widget (took me ages to appreciate this when I first started using Designer). It does not allow you to do so till after the container has had at least one child widget added. This creates a different structure from your "Dragged Vertical Layout from Layouts palette", which you should not do. (Indeed, if you do your way in Designer and look you will see the group box has a "no entry" sign indicating this is incorrect, it is missing its own layout.)

          To address whatever your issue is. By now you have spent a large amount of time asking about your existing, complex code. Instead take the example from https://doc.qt.io/qt-5/qgroupbox.html#details. Get rid of all your code. Does that draw your widgets/group box/layout correctly? Assuming it does, build back from there to your real code, or down from your code to the working code. (For example, get rid of all your parsing code, just test as you incrementally add hard-coded group boxes, layouts and radiobuttons to mirror what you would like to be doing when it's actually reading your XML file.)

          S Offline
          S Offline
          SPlatten
          wrote on 23 Oct 2021, 18:24 last edited by
          #71

          @JonB , I can get it to work easy enough in Qt Creator, but for some reason unknown to me, trying to replicate the same in code doesn't do the same.

          1. I create a QGroupBox
          2. I add two instances of QRadioButton to the QGroupBox by setting the QGroupBox as the parent of the QRadioButton's.
          3. There is no option to select a layout in code so I set the layout using setLayout passing an instance of QVBoxLayout.

          Doing this just ends up with the exact same results, the QGroupBox appears above the radio buttons and the Radio buttons are not inside the QGroupBox. I change the layout to QHBoxLayout no difference in appearance, the radio buttons still appear above each other and outside the QGroupBox.

          Kind Regards,
          Sy

          J 1 Reply Last reply 23 Oct 2021, 19:19
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 23 Oct 2021, 18:32 last edited by
            #72

            In code:

            • create QGroupBox
            • create buttons (no need for parent)
            • create layout (without any parent !)
            • add buttons to layout
            • set layout on QGroupBox

            Other possibility:

            • create QGroupBox
            • create layout (without any parent !)
            • set layout on QGroupBox
            • create buttons (no need for parent)
            • add buttons to layout

            Yet another possibility:

            • create QGroupBox
            • create layout with QGroupBox object as parent
            • create buttons (no need for parent)
            • add buttons to layout

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

            S 1 Reply Last reply 23 Oct 2021, 18:34
            0
            • S SGaist
              23 Oct 2021, 18:32

              In code:

              • create QGroupBox
              • create buttons (no need for parent)
              • create layout (without any parent !)
              • add buttons to layout
              • set layout on QGroupBox

              Other possibility:

              • create QGroupBox
              • create layout (without any parent !)
              • set layout on QGroupBox
              • create buttons (no need for parent)
              • add buttons to layout

              Yet another possibility:

              • create QGroupBox
              • create layout with QGroupBox object as parent
              • create buttons (no need for parent)
              • add buttons to layout
              S Offline
              S Offline
              SPlatten
              wrote on 23 Oct 2021, 18:34 last edited by
              #73

              @SGaist , thank you, will try this now.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • S SPlatten
                23 Oct 2021, 18:24

                @JonB , I can get it to work easy enough in Qt Creator, but for some reason unknown to me, trying to replicate the same in code doesn't do the same.

                1. I create a QGroupBox
                2. I add two instances of QRadioButton to the QGroupBox by setting the QGroupBox as the parent of the QRadioButton's.
                3. There is no option to select a layout in code so I set the layout using setLayout passing an instance of QVBoxLayout.

                Doing this just ends up with the exact same results, the QGroupBox appears above the radio buttons and the Radio buttons are not inside the QGroupBox. I change the layout to QHBoxLayout no difference in appearance, the radio buttons still appear above each other and outside the QGroupBox.

                J Offline
                J Offline
                JonB
                wrote on 23 Oct 2021, 19:19 last edited by JonB
                #74

                @SPlatten said in Layout, widgets not inside ???:

                I create a QGroupBox
                I add two instances of QRadioButton to the QGroupBox by setting the QGroupBox as the parent of the QRadioButton's.
                There is no option to select a layout in code so I set the layout using setLayout passing an instance of QVBoxLayout.

                I referred you to copy from https://doc.qt.io/qt-5/qgroupbox.html#details, all you have to do is copy the code example there. Obviously you have to add buttons onto the layout with QVBoxLayout::addWidget();, else you're not putting them on a layout. Yet you do not mention that in your steps.....??

                S 1 Reply Last reply 23 Oct 2021, 19:23
                0
                • J JonB
                  23 Oct 2021, 19:19

                  @SPlatten said in Layout, widgets not inside ???:

                  I create a QGroupBox
                  I add two instances of QRadioButton to the QGroupBox by setting the QGroupBox as the parent of the QRadioButton's.
                  There is no option to select a layout in code so I set the layout using setLayout passing an instance of QVBoxLayout.

                  I referred you to copy from https://doc.qt.io/qt-5/qgroupbox.html#details, all you have to do is copy the code example there. Obviously you have to add buttons onto the layout with QVBoxLayout::addWidget();, else you're not putting them on a layout. Yet you do not mention that in your steps.....??

                  S Offline
                  S Offline
                  SPlatten
                  wrote on 23 Oct 2021, 19:23 last edited by
                  #75

                  @JonB , I have tried adding the widgets to the layout and also tried using the layout as the parent for the widgets, neither have worked.

                  Kind Regards,
                  Sy

                  J 1 Reply Last reply 23 Oct 2021, 19:28
                  0
                  • S SPlatten
                    23 Oct 2021, 19:23

                    @JonB , I have tried adding the widgets to the layout and also tried using the layout as the parent for the widgets, neither have worked.

                    J Offline
                    J Offline
                    JonB
                    wrote on 23 Oct 2021, 19:28 last edited by
                    #76

                    @SPlatten
                    So, if you just copy the example on the doc page, nothing else, into a standalone program, could you screenshot the result so that we can understand what is wrong?

                    S 1 Reply Last reply 23 Oct 2021, 19:30
                    0
                    • J JonB
                      23 Oct 2021, 19:28

                      @SPlatten
                      So, if you just copy the example on the doc page, nothing else, into a standalone program, could you screenshot the result so that we can understand what is wrong?

                      S Offline
                      S Offline
                      SPlatten
                      wrote on 23 Oct 2021, 19:30 last edited by
                      #77

                      @JonB , just to be clear, is this what you are asking me to try out?

                          QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));
                      
                          QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
                          QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
                          QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
                      
                          radio1->setChecked(true);
                      
                          QVBoxLayout *vbox = new QVBoxLayout;
                          vbox->addWidget(radio1);
                          vbox->addWidget(radio2);
                          vbox->addWidget(radio3);
                          vbox->addStretch(1);
                          groupBox->setLayout(vbox);
                      

                      Kind Regards,
                      Sy

                      J 1 Reply Last reply 23 Oct 2021, 19:31
                      0
                      • S SPlatten
                        23 Oct 2021, 19:30

                        @JonB , just to be clear, is this what you are asking me to try out?

                            QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));
                        
                            QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
                            QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
                            QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
                        
                            radio1->setChecked(true);
                        
                            QVBoxLayout *vbox = new QVBoxLayout;
                            vbox->addWidget(radio1);
                            vbox->addWidget(radio2);
                            vbox->addWidget(radio3);
                            vbox->addStretch(1);
                            groupBox->setLayout(vbox);
                        
                        J Offline
                        J Offline
                        JonB
                        wrote on 23 Oct 2021, 19:31 last edited by
                        #78

                        @SPlatten Yep!

                        S 1 Reply Last reply 23 Oct 2021, 19:31
                        0
                        • J JonB
                          23 Oct 2021, 19:31

                          @SPlatten Yep!

                          S Offline
                          S Offline
                          SPlatten
                          wrote on 23 Oct 2021, 19:31 last edited by
                          #79

                          @JonB , will do.

                          Kind Regards,
                          Sy

                          J 1 Reply Last reply 23 Oct 2021, 19:36
                          0
                          • S SPlatten
                            23 Oct 2021, 19:31

                            @JonB , will do.

                            J Offline
                            J Offline
                            JonB
                            wrote on 23 Oct 2021, 19:36 last edited by JonB
                            #80

                            @SPlatten
                            :)

                            And I see there is a bigger example at https://doc.qt.io/qt-5/qtwidgets-widgets-groupbox-example.html, but just the standalone one should do.

                            On a separate note, and not wanting to distract you from the task at hand. You seem to have said that you can get what you want from Designer? But not from your own code. And you're not sure what Designer way has done it? But when you build you run uic on the .ui file and (IIRC) it generates ui_yourfile.h. In that is setupUi(). And that is all the code implementing whatever you have designed, there isn't anything else to it. So that code must show you how they produce what you say works?

                            S 1 Reply Last reply 24 Oct 2021, 07:31
                            0
                            • J JonB
                              23 Oct 2021, 19:36

                              @SPlatten
                              :)

                              And I see there is a bigger example at https://doc.qt.io/qt-5/qtwidgets-widgets-groupbox-example.html, but just the standalone one should do.

                              On a separate note, and not wanting to distract you from the task at hand. You seem to have said that you can get what you want from Designer? But not from your own code. And you're not sure what Designer way has done it? But when you build you run uic on the .ui file and (IIRC) it generates ui_yourfile.h. In that is setupUi(). And that is all the code implementing whatever you have designed, there isn't anything else to it. So that code must show you how they produce what you say works?

                              S Offline
                              S Offline
                              SPlatten
                              wrote on 24 Oct 2021, 07:31 last edited by
                              #81

                              @JonB , I've used Qt Creator to create a mock layout, adding a Group Box, 3 x Radio Buttons then selected Lay Out Vertically from the Lay Out context submenu. Closed UI, clicked on Run qmake then opened up ui_clsMainWnd.h and searched for groupBox, this I the code:

                              groupBox = new QGroupBox(centralWidget);
                              groupBox->setObjectName(QString::fromUtf8("groupBox"));
                              groupBox->setGeometry(QRect(340, 210, 127, 101));
                              verticalLayout = new QVBoxLayout(groupBox);
                              verticalLayout->setSpacing(6);
                              verticalLayout->setContentsMargins(11, 11, 11, 11);
                              verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
                              radioButton = new QRadioButton(groupBox);
                              radioButton->setObjectName(QString::fromUtf8("radioButton"));
                              
                              verticalLayout->addWidget(radioButton);
                              
                              radioButton_2 = new QRadioButton(groupBox);
                              radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
                              
                              verticalLayout->addWidget(radioButton_2);
                              
                              radioButton_3 = new QRadioButton(groupBox);
                              radioButton_3->setObjectName(QString::fromUtf8("radioButton_3"));
                              
                              verticalLayout->addWidget(radioButton_3);
                              

                              This all looks good, I assume that 6 used or spacing is just a default along with the margins 11. I may have to experiment with the geometry 340, 210, 127, 101.

                              Kind Regards,
                              Sy

                              J 1 Reply Last reply 24 Oct 2021, 07:50
                              0
                              • S SPlatten
                                24 Oct 2021, 07:31

                                @JonB , I've used Qt Creator to create a mock layout, adding a Group Box, 3 x Radio Buttons then selected Lay Out Vertically from the Lay Out context submenu. Closed UI, clicked on Run qmake then opened up ui_clsMainWnd.h and searched for groupBox, this I the code:

                                groupBox = new QGroupBox(centralWidget);
                                groupBox->setObjectName(QString::fromUtf8("groupBox"));
                                groupBox->setGeometry(QRect(340, 210, 127, 101));
                                verticalLayout = new QVBoxLayout(groupBox);
                                verticalLayout->setSpacing(6);
                                verticalLayout->setContentsMargins(11, 11, 11, 11);
                                verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
                                radioButton = new QRadioButton(groupBox);
                                radioButton->setObjectName(QString::fromUtf8("radioButton"));
                                
                                verticalLayout->addWidget(radioButton);
                                
                                radioButton_2 = new QRadioButton(groupBox);
                                radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
                                
                                verticalLayout->addWidget(radioButton_2);
                                
                                radioButton_3 = new QRadioButton(groupBox);
                                radioButton_3->setObjectName(QString::fromUtf8("radioButton_3"));
                                
                                verticalLayout->addWidget(radioButton_3);
                                

                                This all looks good, I assume that 6 used or spacing is just a default along with the margins 11. I may have to experiment with the geometry 340, 210, 127, 101.

                                J Offline
                                J Offline
                                JonB
                                wrote on 24 Oct 2021, 07:50 last edited by
                                #82

                                @SPlatten
                                Not sure what the question is here. Does "This all looks good" mean that when run it does indeed draw the radiobuttons correctly within their layout, as you have been trying to do in code but unsuccessfully?

                                You can see the code is exactly what I said and in the code example in the docs for QGroupBox. Create a QGroupBox, put a QVBoxLayout on it, add QRadioButtons onto the layout. That is all you should ever do.

                                The setGeometry() just corresponds to the position & size of the groupbox you have on your design canvas. I would not have thought you would need to do that, the QGroupBox should resize to correctly enclose its content. The spacing and margins are just defaults used by Designer, you can alter them.

                                You can play with this code in the ui_clsMainWnd.h file by editing, it will not get overwritten unless you alter the .ui file. And/or you can copy it to your own code and play with it there.

                                Whatever the difference from your own code which has not been working, you should be in a good position to discover that from here.

                                S 1 Reply Last reply 24 Oct 2021, 07:51
                                0
                                • J JonB
                                  24 Oct 2021, 07:50

                                  @SPlatten
                                  Not sure what the question is here. Does "This all looks good" mean that when run it does indeed draw the radiobuttons correctly within their layout, as you have been trying to do in code but unsuccessfully?

                                  You can see the code is exactly what I said and in the code example in the docs for QGroupBox. Create a QGroupBox, put a QVBoxLayout on it, add QRadioButtons onto the layout. That is all you should ever do.

                                  The setGeometry() just corresponds to the position & size of the groupbox you have on your design canvas. I would not have thought you would need to do that, the QGroupBox should resize to correctly enclose its content. The spacing and margins are just defaults used by Designer, you can alter them.

                                  You can play with this code in the ui_clsMainWnd.h file by editing, it will not get overwritten unless you alter the .ui file. And/or you can copy it to your own code and play with it there.

                                  Whatever the difference from your own code which has not been working, you should be in a good position to discover that from here.

                                  S Offline
                                  S Offline
                                  SPlatten
                                  wrote on 24 Oct 2021, 07:51 last edited by
                                  #83

                                  @JonB , sorry, yes, what I should have said, is that everything in my last post renders the correct solution and looks good, which I am now trying to replicate in my code, given that the XML is dynamic.

                                  Kind Regards,
                                  Sy

                                  J 1 Reply Last reply 24 Oct 2021, 07:55
                                  0
                                  • S SPlatten
                                    24 Oct 2021, 07:51

                                    @JonB , sorry, yes, what I should have said, is that everything in my last post renders the correct solution and looks good, which I am now trying to replicate in my code, given that the XML is dynamic.

                                    J Offline
                                    J Offline
                                    JonB
                                    wrote on 24 Oct 2021, 07:55 last edited by
                                    #84

                                    @SPlatten
                                    Indeed, you must just make sure that what you come up from your parsing-creating-dynamically matches the static pattern you know works.

                                    Everything has always felt like the radiobuttons are being added onto the QGroupBox directly where they need to be added onto the QVBoxLayout (and of course that must be set as the group box's layout).

                                    S 1 Reply Last reply 24 Oct 2021, 15:33
                                    0
                                    • J JonB
                                      24 Oct 2021, 07:55

                                      @SPlatten
                                      Indeed, you must just make sure that what you come up from your parsing-creating-dynamically matches the static pattern you know works.

                                      Everything has always felt like the radiobuttons are being added onto the QGroupBox directly where they need to be added onto the QVBoxLayout (and of course that must be set as the group box's layout).

                                      S Offline
                                      S Offline
                                      SPlatten
                                      wrote on 24 Oct 2021, 15:33 last edited by SPlatten
                                      #85

                                      @JonB , been out all day, just got back to trying out the stand along demo and no problems, it works:

                                      #include "mainwindow.h"
                                      
                                      #include <QApplication>
                                      #include <QGroupBox>
                                      #include <QRadioButton>
                                      #include <QVBoxLayout>
                                      
                                      int main(int argc, char *argv[])
                                      {
                                          QApplication a(argc, argv);
                                          MainWindow w;
                                      
                                          QGroupBox* groupBox = new QGroupBox(w.centralWidget());
                                          groupBox->setTitle("Demo");
                                          groupBox->setObjectName(QString::fromUtf8("groupBox"));
                                          groupBox->setGeometry(QRect(20, 110, 127, 101));
                                          QVBoxLayout* verticalLayout = new QVBoxLayout(groupBox);
                                          verticalLayout->setSpacing(6);
                                          verticalLayout->setContentsMargins(11, 11, 11, 11);
                                          verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
                                          QRadioButton* radioButton = new QRadioButton(groupBox);
                                          radioButton->setObjectName(QString::fromUtf8("radioButton"));
                                          radioButton->setText("Radio 1");
                                          verticalLayout->addWidget(radioButton);
                                      
                                          QRadioButton* radioButton_2 = new QRadioButton(groupBox);
                                          radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
                                          radioButton_2->setText("Radio 2");
                                          verticalLayout->addWidget(radioButton_2);
                                      
                                          QRadioButton* radioButton_3 = new QRadioButton(groupBox);
                                          radioButton_3->setObjectName(QString::fromUtf8("radioButton_3"));
                                          radioButton_3->setText("Radio 3");
                                          verticalLayout->addWidget(radioButton_3);
                                      
                                          w.show();
                                          return a.exec();
                                      }
                                      

                                      Screenshot 2021-10-24 at 16.32.43.png

                                      Which means I need to did around in my engine and find out why the same doesn't work when I repeat in my engine.

                                      Debugger, watch window:
                                      Screenshot 2021-10-24 at 16.36.13.png

                                      Kind Regards,
                                      Sy

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 24 Oct 2021, 18:04 last edited by
                                        #86

                                        As suggested before, you should simplify your code and approach the interface building in a simpler manner.

                                        For your xml, you should pass it through a validator to ensure that what you parse is what your application expects. With that you can remove quite a lot of manual verifications.

                                        Split your widget generation in smaller functions. It's harder to reason in one mega function that does everything.

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

                                        S 1 Reply Last reply 24 Oct 2021, 18:55
                                        1
                                        • S SGaist
                                          24 Oct 2021, 18:04

                                          As suggested before, you should simplify your code and approach the interface building in a simpler manner.

                                          For your xml, you should pass it through a validator to ensure that what you parse is what your application expects. With that you can remove quite a lot of manual verifications.

                                          Split your widget generation in smaller functions. It's harder to reason in one mega function that does everything.

                                          S Offline
                                          S Offline
                                          SPlatten
                                          wrote on 24 Oct 2021, 18:55 last edited by
                                          #87

                                          @SGaist , the engine is quite simple, I just need to identify what is different, I will start by comparing the tree structure.

                                          Kind Regards,
                                          Sy

                                          1 Reply Last reply
                                          0

                                          77/87

                                          23 Oct 2021, 19:30

                                          • Login

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