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 10.1k 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.
  • SPlattenS SPlatten

    @JoeCFD , This was just an exercise using Qt Creator to see what it does and why the works compared to coding it by hand....

    JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by JoeCFD
    #46

    @SPlatten
    group layout

    SPlattenS 1 Reply Last reply
    0
    • JoeCFDJ JoeCFD

      @SPlatten
      group layout

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #47

      @JoeCFD , can you not paste the source or post what you did?

      Kind Regards,
      Sy

      1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #48

        link added

        SPlattenS 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          link added

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #49

          @JoeCFD , thank you, I'm still trying to see why I cannot replicate in code what the WYSIWYG editor does.

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #50

            I thought I'd hit on something, I found another post online and added:

            pobjLayout->addItem(new QWidgetItem(pobjWidget));
            

            No joy, still doesn't work! Looking at the layout in the debugger, after executing this line, there are no additions to the children, same with addWidget...so what do I have to do?

            Kind Regards,
            Sy

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

              Provide a minimal compilable example of that specific part of your code so that people can experiment with it.

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

              SPlattenS 1 Reply Last reply
              2
              • SGaistS SGaist

                Provide a minimal compilable example of that specific part of your code so that people can experiment with it.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by SPlatten
                #52

                @SGaist , this is difficult, but I will try:

                This is the 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>
                

                I have quite a lot of code that parses all the various node types, here is the bit for the above:

                            if ( pobjParent != nullptr ) {
                    //Does the parent have a layout?
                                pobjLayout = pobjParent->pobjGetLayout();
                                if ( pobjLayout != nullptr ) {
                    //Yes, clear the pobjParWidget widget
                                    pobjParWidget = nullptr;
                                }
                            }
                            pobjWidget = qobject_cast<QWidget*>(clsCNT::pCreate(this,
                                                                                mstrName,
                                                                                strCSS,
                                                                                slstProperties,
                                                                                pobjParWidget));
                

                The above code calls pCreate which based on the content of mstrName creates the widget:

                QWidget* clsCNT::pCreate(clsXMLnode* pobjNode, const QString& crstrType
                                        ,QString& rstrCSS, QStringList& rslstProperties
                                        ,QWidget* pobjParent) {
                    if ( clsCNT::blnValidType(crstrType) == true ) {
                        if ( crstrType.compare(clsCNT::mscszButton) == 0 ) {
                            return new clsQtPushBtn(pobjNode, &rstrCSS, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszCheckbox) == 0 ) {
                            return new clsQtCheckBox(pobjNode, &rstrCSS, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszCombo) == 0 ) {
                            return new clsQtComboBox(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                        } else if( crstrType.compare(clsCNT::mscszFrame) == 0 ) {
                            return new clsQtFrame(pobjNode, &rstrCSS, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszGroupBox) == 0 ) {
                            return new clsQtGroupBox(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszLabel) == 0 ) {
                            return new clsQtLabel(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszLineEdit) == 0 ) {
                            return new clsQtLineEdit(pobjNode, &rstrCSS, &rslstProperties, pobjParent);            
                        } else if ( crstrType.compare(clsCNT::mscszListWidget) == 0 ) {
                            return new clsQtListWidget(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszRadioButton) == 0 ) {
                            return new clsQtRadioButton(pobjNode, &rstrCSS, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszSliderVert) == 0 ) {
                            return new clsQtSlider(Qt::Vertical, pobjNode, &rstrCSS, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszSliderHorz) == 0 ) {
                            return new clsQtSlider(Qt::Horizontal, pobjNode, &rstrCSS, pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszSpinBox) == 0 ) {
                            return new QSpinBox(pobjParent);
                        } else if ( crstrType.compare(clsCNT::mscszTextEdit) == 0 ) {
                            return new clsQtTextEdit(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                        }
                    }
                    return nullptr;
                }
                

                Give the widget a human readable name and add it to the layout if one exists:

                        if ( pobjWidget != nullptr ) {
                //Set the object name
                            QString strID(strGetAttribute(clsXMLnode::mscszAttrID)),
                                    strName(mstrName);
                            if ( strID.isEmpty() != true ) {
                                strName += ", id: " + strID;
                            }
                            pobjWidget->setObjectName(strName);
                        }
                        if ( pobjLayout != nullptr ) {
                //Any alignment?
                            QString strAlign(pobjParent->strGetAttribute(clsXMLnode::mscszAttrAlignment));
                            Qt::Alignment eCellAlign(Qt::AlignVCenter | Qt::AlignHCenter);
                            if ( strAlign.compare(clsXMLnode::mscszGeomCenter) == 0 ) {
                                eCellAlign |= Qt::AlignHCenter;
                            } else if ( strAlign.compare(clsXMLnode::mscszGeomLeft) == 0 ) {
                                eCellAlign |= Qt::AlignLeft;
                            } else if ( strAlign.compare(clsXMLnode::mscszGeomRight) == 0 ) {
                                eCellAlign |= Qt::AlignRight;
                            }
                //Add the widget to the layout
                            QLayoutItem* pobjItem(new QWidgetItem(pobjWidget));
                            pobjItem->setAlignment(eCellAlign);
                            pobjLayout->addItem(pobjItem);
                //            pobjLayout->addWidget(pobjWidget);
                        }
                

                Hopefully this is enough, however at this point I really don't think its something I've done wrong but a limitation or restriction in Qt, bearing in mind that my code does this all at run-time where as the UI create in Qt is parsed when the project is compiled.

                [Edit], I just decided to debug again and single stepped into addItem, interesting:

                void QBoxLayout::addItem(QLayoutItem *item)
                {
                    Q_D(QBoxLayout);
                    QBoxLayoutItem *it = new QBoxLayoutItem(item);
                    d->list.append(it);
                    invalidate();
                }
                

                When I get into addItem, on QBoxLayoutItem *it = new QBoxLayoutItem(item);:
                Screenshot 2021-10-20 at 20.25.33.png

                If I click on Step Over twice, the cursor is pointing to invalidate();, the watch window has changed to:
                Screenshot 2021-10-20 at 20.27.08.png

                Looks very wrong and after returning back to where the call took place there is no addition to the layout.

                addWidget calls addItem internally, so if its a bug in addItem this explains everything.

                [Edit 2] I have file a bug:
                https://bugreports.qt.io/browse/QTBUG-97662

                Kind Regards,
                Sy

                JKSHJ 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @SGaist , this is difficult, but I will try:

                  This is the 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>
                  

                  I have quite a lot of code that parses all the various node types, here is the bit for the above:

                              if ( pobjParent != nullptr ) {
                      //Does the parent have a layout?
                                  pobjLayout = pobjParent->pobjGetLayout();
                                  if ( pobjLayout != nullptr ) {
                      //Yes, clear the pobjParWidget widget
                                      pobjParWidget = nullptr;
                                  }
                              }
                              pobjWidget = qobject_cast<QWidget*>(clsCNT::pCreate(this,
                                                                                  mstrName,
                                                                                  strCSS,
                                                                                  slstProperties,
                                                                                  pobjParWidget));
                  

                  The above code calls pCreate which based on the content of mstrName creates the widget:

                  QWidget* clsCNT::pCreate(clsXMLnode* pobjNode, const QString& crstrType
                                          ,QString& rstrCSS, QStringList& rslstProperties
                                          ,QWidget* pobjParent) {
                      if ( clsCNT::blnValidType(crstrType) == true ) {
                          if ( crstrType.compare(clsCNT::mscszButton) == 0 ) {
                              return new clsQtPushBtn(pobjNode, &rstrCSS, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszCheckbox) == 0 ) {
                              return new clsQtCheckBox(pobjNode, &rstrCSS, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszCombo) == 0 ) {
                              return new clsQtComboBox(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                          } else if( crstrType.compare(clsCNT::mscszFrame) == 0 ) {
                              return new clsQtFrame(pobjNode, &rstrCSS, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszGroupBox) == 0 ) {
                              return new clsQtGroupBox(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszLabel) == 0 ) {
                              return new clsQtLabel(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszLineEdit) == 0 ) {
                              return new clsQtLineEdit(pobjNode, &rstrCSS, &rslstProperties, pobjParent);            
                          } else if ( crstrType.compare(clsCNT::mscszListWidget) == 0 ) {
                              return new clsQtListWidget(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszRadioButton) == 0 ) {
                              return new clsQtRadioButton(pobjNode, &rstrCSS, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszSliderVert) == 0 ) {
                              return new clsQtSlider(Qt::Vertical, pobjNode, &rstrCSS, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszSliderHorz) == 0 ) {
                              return new clsQtSlider(Qt::Horizontal, pobjNode, &rstrCSS, pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszSpinBox) == 0 ) {
                              return new QSpinBox(pobjParent);
                          } else if ( crstrType.compare(clsCNT::mscszTextEdit) == 0 ) {
                              return new clsQtTextEdit(pobjNode, &rstrCSS, &rslstProperties, pobjParent);
                          }
                      }
                      return nullptr;
                  }
                  

                  Give the widget a human readable name and add it to the layout if one exists:

                          if ( pobjWidget != nullptr ) {
                  //Set the object name
                              QString strID(strGetAttribute(clsXMLnode::mscszAttrID)),
                                      strName(mstrName);
                              if ( strID.isEmpty() != true ) {
                                  strName += ", id: " + strID;
                              }
                              pobjWidget->setObjectName(strName);
                          }
                          if ( pobjLayout != nullptr ) {
                  //Any alignment?
                              QString strAlign(pobjParent->strGetAttribute(clsXMLnode::mscszAttrAlignment));
                              Qt::Alignment eCellAlign(Qt::AlignVCenter | Qt::AlignHCenter);
                              if ( strAlign.compare(clsXMLnode::mscszGeomCenter) == 0 ) {
                                  eCellAlign |= Qt::AlignHCenter;
                              } else if ( strAlign.compare(clsXMLnode::mscszGeomLeft) == 0 ) {
                                  eCellAlign |= Qt::AlignLeft;
                              } else if ( strAlign.compare(clsXMLnode::mscszGeomRight) == 0 ) {
                                  eCellAlign |= Qt::AlignRight;
                              }
                  //Add the widget to the layout
                              QLayoutItem* pobjItem(new QWidgetItem(pobjWidget));
                              pobjItem->setAlignment(eCellAlign);
                              pobjLayout->addItem(pobjItem);
                  //            pobjLayout->addWidget(pobjWidget);
                          }
                  

                  Hopefully this is enough, however at this point I really don't think its something I've done wrong but a limitation or restriction in Qt, bearing in mind that my code does this all at run-time where as the UI create in Qt is parsed when the project is compiled.

                  [Edit], I just decided to debug again and single stepped into addItem, interesting:

                  void QBoxLayout::addItem(QLayoutItem *item)
                  {
                      Q_D(QBoxLayout);
                      QBoxLayoutItem *it = new QBoxLayoutItem(item);
                      d->list.append(it);
                      invalidate();
                  }
                  

                  When I get into addItem, on QBoxLayoutItem *it = new QBoxLayoutItem(item);:
                  Screenshot 2021-10-20 at 20.25.33.png

                  If I click on Step Over twice, the cursor is pointing to invalidate();, the watch window has changed to:
                  Screenshot 2021-10-20 at 20.27.08.png

                  Looks very wrong and after returning back to where the call took place there is no addition to the layout.

                  addWidget calls addItem internally, so if its a bug in addItem this explains everything.

                  [Edit 2] I have file a bug:
                  https://bugreports.qt.io/browse/QTBUG-97662

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by JKSH
                  #53

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

                  my code does this all at run-time where as the UI create in Qt is parsed when the project is compiled.

                  While Qt Designer's .ui files are parsed at compile time, the parser generates C++ code that runs at runtime.

                  You said that the WYSIWYG editor works. So, build a working GUI and then inspect the ui_*.h file that is generated in your build folder. Copy the code inside the setupUi() method.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  SPlattenS 2 Replies Last reply
                  4
                  • JKSHJ JKSH

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

                    my code does this all at run-time where as the UI create in Qt is parsed when the project is compiled.

                    While Qt Designer's .ui files are parsed at compile time, the parser generates C++ code that runs at runtime.

                    You said that the WYSIWYG editor works. So, build a working GUI and then inspect the ui_*.h file that is generated in your build folder. Copy the code inside the setupUi() method.

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #54

                    @JKSH , thank you, I will take a look.

                    Kind Regards,
                    Sy

                    1 Reply Last reply
                    0
                    • JKSHJ JKSH

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

                      my code does this all at run-time where as the UI create in Qt is parsed when the project is compiled.

                      While Qt Designer's .ui files are parsed at compile time, the parser generates C++ code that runs at runtime.

                      You said that the WYSIWYG editor works. So, build a working GUI and then inspect the ui_*.h file that is generated in your build folder. Copy the code inside the setupUi() method.

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by SPlatten
                      #55

                      @JKSH , this is from the header file:

                          QGroupBox *groupBox;
                          QWidget *verticalLayoutWidget;
                          QVBoxLayout *verticalLayout;
                          QRadioButton *Radio1;
                          QRadioButton *Radio2;
                          QRadioButton *Radio3;
                      

                      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.

                      Then there is this code:

                              groupBox = new QGroupBox(centralWidget);
                              groupBox->setObjectName(QString::fromUtf8("groupBox"));
                              groupBox->setGeometry(QRect(120, 170, 301, 201));
                              verticalLayoutWidget = new QWidget(groupBox);
                              verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget"));
                              verticalLayoutWidget->setGeometry(QRect(9, 29, 291, 161));
                              verticalLayout = new QVBoxLayout(verticalLayoutWidget);
                              verticalLayout->setSpacing(6);
                              verticalLayout->setContentsMargins(11, 11, 11, 11);
                              verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
                              verticalLayout->setContentsMargins(0, 0, 0, 0);
                              Radio1 = new QRadioButton(verticalLayoutWidget);
                              Radio1->setObjectName(QString::fromUtf8("Radio1"));
                      
                              verticalLayout->addWidget(Radio1);
                      
                              Radio2 = new QRadioButton(verticalLayoutWidget);
                              Radio2->setObjectName(QString::fromUtf8("Radio2"));
                      
                              verticalLayout->addWidget(Radio2);
                      
                              Radio3 = new QRadioButton(verticalLayoutWidget);
                              Radio3->setObjectName(QString::fromUtf8("Radio3"));
                      
                              verticalLayout->addWidget(Radio3);
                      

                      Which clearly creates a new widget and positions it between QGroupBox and QVBoxLayout.

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0
                      • JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote on last edited by
                        #56

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

                        Which clearly creates a new widget and positions it between QGroupBox and QVBoxLayout.

                        What is for? The gaps between verticalLayoutWidget and groupBox can be handled with verticalLayout->setContentsMargins(11, 11, 11, 11); verticalLayoutWidget is not needed. Check the example in my link.

                        SPlattenS 1 Reply Last reply
                        0
                        • JoeCFDJ JoeCFD

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

                          Which clearly creates a new widget and positions it between QGroupBox and QVBoxLayout.

                          What is for? The gaps between verticalLayoutWidget and groupBox can be handled with verticalLayout->setContentsMargins(11, 11, 11, 11); verticalLayoutWidget is not needed. Check the example in my link.

                          SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by
                          #57

                          @JoeCFD , I think you misunderstand what I am saying. I used Qt Creator to build this example, I did the following:

                          • Dragged Group Box from Containers palette and dropped onto centralWidget
                          • Dragged Vertical Layout from Layouts palette and dropped onto Group Box
                          • Dragged Radio Button from Buttons palette and dropped onto Vertical Layout
                          • Dragged Radio Button from Buttons palette and dropped onto Vertical Layout
                          • Dragged Radio Button from Buttons palette and dropped onto Vertical Layout
                          • Edited text attribute for each control

                          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.

                          Kind Regards,
                          Sy

                          JoeCFDJ 1 Reply Last reply
                          0
                          • SPlattenS SPlatten

                            @JoeCFD , I think you misunderstand what I am saying. I used Qt Creator to build this example, I did the following:

                            • Dragged Group Box from Containers palette and dropped onto centralWidget
                            • Dragged Vertical Layout from Layouts palette and dropped onto Group Box
                            • Dragged Radio Button from Buttons palette and dropped onto Vertical Layout
                            • Dragged Radio Button from Buttons palette and dropped onto Vertical Layout
                            • Dragged Radio Button from Buttons palette and dropped onto Vertical Layout
                            • Edited text attribute for each control

                            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.

                            JoeCFDJ Offline
                            JoeCFDJ Offline
                            JoeCFD
                            wrote on last edited by
                            #58

                            @SPlatten Nothing wrong with it. In your case, I think you do not need it. It is better to understand how this works. I did the same thing in my link with designer which does not have verticalLayoutWidget.

                                    groupBox = new QGroupBox(centralwidget);
                                    groupBox->setObjectName(QString::fromUtf8("groupBox"));
                                    verticalLayout = new QVBoxLayout(groupBox);
                                    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);
                            
                            
                            SPlattenS 1 Reply Last reply
                            1
                            • JoeCFDJ JoeCFD

                              @SPlatten Nothing wrong with it. In your case, I think you do not need it. It is better to understand how this works. I did the same thing in my link with designer which does not have verticalLayoutWidget.

                                      groupBox = new QGroupBox(centralwidget);
                                      groupBox->setObjectName(QString::fromUtf8("groupBox"));
                                      verticalLayout = new QVBoxLayout(groupBox);
                                      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);
                              
                              
                              SPlattenS Offline
                              SPlattenS Offline
                              SPlatten
                              wrote on last edited by
                              #59

                              @JoeCFD , difference I can see is you set the parent for the radio buttons to group box, if this is correct then this is where I'm going wrong, because I'm setting the parent to the layout.

                              Kind Regards,
                              Sy

                              JoeCFDJ 1 Reply Last reply
                              0
                              • SPlattenS SPlatten

                                @JoeCFD , difference I can see is you set the parent for the radio buttons to group box, if this is correct then this is where I'm going wrong, because I'm setting the parent to the layout.

                                JoeCFDJ Offline
                                JoeCFDJ Offline
                                JoeCFD
                                wrote on last edited by JoeCFD
                                #60

                                @SPlatten If verticalLayoutWidget does not exist, groupBox is a natural choice. You can set their parents to be central widget as well. It is layouts which hold and organize widgets. Children are cleared when their parents are destroyed.

                                Sometimes, I need to move a widget to another place in my app. What I do is to remove its parent first and add a new parent. Then add it to the layout of the new parent.

                                An overlaid widget is made within its parent widget without being placed in any layout. Sure an overlaid widget can have a layout. In your case, verticalLayoutWidget is an overlaid widget since it is not in any layout.

                                SPlattenS 1 Reply Last reply
                                0
                                • JoeCFDJ JoeCFD

                                  @SPlatten If verticalLayoutWidget does not exist, groupBox is a natural choice. You can set their parents to be central widget as well. It is layouts which hold and organize widgets. Children are cleared when their parents are destroyed.

                                  Sometimes, I need to move a widget to another place in my app. What I do is to remove its parent first and add a new parent. Then add it to the layout of the new parent.

                                  An overlaid widget is made within its parent widget without being placed in any layout. Sure an overlaid widget can have a layout. In your case, verticalLayoutWidget is an overlaid widget since it is not in any layout.

                                  SPlattenS Offline
                                  SPlattenS Offline
                                  SPlatten
                                  wrote on last edited by
                                  #61

                                  @JoeCFD Well I've tried setting the parent to the groupbox, still the same, not right.

                                  Kind Regards,
                                  Sy

                                  1 Reply Last reply
                                  0
                                  • JoeCFDJ Offline
                                    JoeCFDJ Offline
                                    JoeCFD
                                    wrote on last edited by JoeCFD
                                    #62

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

                                    verticalLayoutWidget->setGeometry(QRect(9, 29, 291, 161))

                                    your verticalLayoutWidget height is 161 and vertical margins of the layout are 11 * 2; The layout height for your radio buttons is 161 - 23 = 138 px. What is the height of your single radio button?

                                    what is the central widget width and height?
                                    groupBox->setGeometry(QRect(120, 170, 301, 201));
                                    its width has at least 120 + 301 px.

                                    SPlattenS 1 Reply Last reply
                                    0
                                    • JoeCFDJ JoeCFD

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

                                      verticalLayoutWidget->setGeometry(QRect(9, 29, 291, 161))

                                      your verticalLayoutWidget height is 161 and vertical margins of the layout are 11 * 2; The layout height for your radio buttons is 161 - 23 = 138 px. What is the height of your single radio button?

                                      what is the central widget width and height?
                                      groupBox->setGeometry(QRect(120, 170, 301, 201));
                                      its width has at least 120 + 301 px.

                                      SPlattenS Offline
                                      SPlattenS Offline
                                      SPlatten
                                      wrote on last edited by
                                      #63

                                      @JoeCFD, I thought the widget containing the layout and other widgets would auto size ?

                                      Kind Regards,
                                      Sy

                                      JKSHJ JoeCFDJ 2 Replies Last reply
                                      0
                                      • SPlattenS SPlatten

                                        @JoeCFD, I thought the widget containing the layout and other widgets would auto size ?

                                        JKSHJ Offline
                                        JKSHJ Offline
                                        JKSH
                                        Moderators
                                        wrote on last edited by
                                        #64

                                        @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".

                                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                        SPlattenS 2 Replies Last reply
                                        4
                                        • JKSHJ JKSH

                                          @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".

                                          SPlattenS Offline
                                          SPlattenS Offline
                                          SPlatten
                                          wrote on last edited by
                                          #65

                                          @JKSH , thank you, I will certainly give it a go.

                                          Kind Regards,
                                          Sy

                                          1 Reply Last reply
                                          0

                                          • Login

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