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. Embed form into tab on main window
Forum Updated to NodeBB v4.3 + New Features

Embed form into tab on main window

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 754 Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    What exactly is your issue with the current code ?

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

      The controls in the form are not showing up. fa59b974-e59b-483e-b922-8415e885a484-image.png

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

        Since you did not provide comms, I do not know whether there's something wrong with it.

        So I modified your script to show a QLabel instead and it works.

        # This Python file uses the following encoding: utf-8
        import sys
        
        from PySide2.QtWidgets import (
            QApplication,
            QDialog,
            QTabWidget,
            QWidget,
            QVBoxLayout,
            QPushButton,
            QLabel,
        )
        
        
        class Configuration(QDialog):
            def __init__(self, parent=None):
                super(Configuration, self).__init__(parent)
                self.setWindowTitle("Configuration Dialog")
                tabWidget = QTabWidget()
                tabWidget.addTab(FirstTab(self), "COMMS")
                vbox = QVBoxLayout()
                vbox.addWidget(tabWidget)
                self.setLayout(vbox)
        
        
        # If I don't use the tab, I can launch the form from here
        class MyWidget(QWidget):
            def __init__(self):
                super().__init__()
                # self.ui = comms.Ui_Form()
                # self.ui.setupUi(self)
                label = QLabel(self.tr("Test"))
                vbox = QVBoxLayout(self)
                vbox.addWidget(label)
        
        
        class FirstTab(QWidget):
            def __init__(self, parent):
                super(FirstTab, self).__init__(parent)
                vbox = QVBoxLayout()
                mywidget = MyWidget()
                vbox.addWidget(mywidget)
                self.setLayout(vbox)
        
        
        if __name__ == "__main__":
            app = QApplication(sys.argv)
            app.setStyle("fusion")
            configuration = Configuration()
            configuration.show()
            sys.exit(app.exec_())
        

        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
        0
        • S Offline
          S Offline
          StephvanS
          wrote on last edited by StephvanS
          #5

          Yes, I can display other widgets in the tab. That's why it is so flabbergasting.
          Here is the form. It is stock from pyside-uic.

          # -*- coding: utf-8 -*-
          
          ################################################################################
          ## Form generated from reading UI file 'comms.ui'
          ##
          ## Created by: Qt User Interface Compiler version 5.15.1
          ##
          ## WARNING! All changes made in this file will be lost when recompiling UI file!
          ################################################################################
          
          from PySide2.QtCore import *
          from PySide2.QtGui import *
          from PySide2.QtWidgets import *
          
          
          class Ui_Form(object):
              def setupUi(self, Form):
                  if not Form.objectName():
                      Form.setObjectName(u"Form")
                  Form.resize(800, 400)
                  Form.setAutoFillBackground(False)
                  self.slComms = QSlider(Form)
                  self.slComms.setObjectName(u"slComms")
                  self.slComms.setGeometry(QRect(300, 270, 161, 16))
                  font = QFont()
                  font.setPointSize(16)
                  self.slComms.setFont(font)
                  self.slComms.setMaximum(1)
                  self.slComms.setPageStep(1)
                  self.slComms.setOrientation(Qt.Horizontal)
                  self.widget = QWidget(Form)
                  self.widget.setObjectName(u"widget")
                  self.widget.setGeometry(QRect(0, 30, 391, 227))
                  self.gridLayout = QGridLayout(self.widget)
                  self.gridLayout.setObjectName(u"gridLayout")
                  self.gridLayout.setContentsMargins(0, 0, 0, 0)
                  self.label_28 = QLabel(self.widget)
                  self.label_28.setObjectName(u"label_28")
                  font1 = QFont()
                  font1.setFamily(u"DejaVu Sans")
                  font1.setPointSize(16)
                  self.label_28.setFont(font1)
          
                  self.gridLayout.addWidget(self.label_28, 0, 0, 1, 2)
          
                  self.label_35 = QLabel(self.widget)
                  self.label_35.setObjectName(u"label_35")
                  self.label_35.setFont(font1)
          
                  self.gridLayout.addWidget(self.label_35, 1, 0, 1, 1)
          
                  self.sbCOM = QSpinBox(self.widget)
                  self.sbCOM.setObjectName(u"sbCOM")
                  self.sbCOM.setFont(font)
          
                  self.gridLayout.addWidget(self.sbCOM, 1, 1, 1, 1)
          
                  self.label_33 = QLabel(self.widget)
                  self.label_33.setObjectName(u"label_33")
                  self.label_33.setFont(font1)
          
                  self.gridLayout.addWidget(self.label_33, 2, 0, 1, 1)
          
                  self.spBps = QSpinBox(self.widget)
                  self.spBps.setObjectName(u"spBps")
                  self.spBps.setFont(font)
          
                  self.gridLayout.addWidget(self.spBps, 2, 1, 1, 1)
          
                  self.label_24 = QLabel(self.widget)
                  self.label_24.setObjectName(u"label_24")
                  self.label_24.setFont(font1)
          
                  self.gridLayout.addWidget(self.label_24, 3, 0, 1, 1)
          
                  self.spBits = QSpinBox(self.widget)
                  self.spBits.setObjectName(u"spBits")
                  self.spBits.setFont(font)
          
                  self.gridLayout.addWidget(self.spBits, 3, 1, 1, 1)
          
                  self.label_25 = QLabel(self.widget)
                  self.label_25.setObjectName(u"label_25")
                  self.label_25.setFont(font1)
          
                  self.gridLayout.addWidget(self.label_25, 4, 0, 1, 1)
          
                  self.spParity = QSpinBox(self.widget)
                  self.spParity.setObjectName(u"spParity")
                  self.spParity.setFont(font)
          
                  self.gridLayout.addWidget(self.spParity, 4, 1, 1, 1)
          
                  self.label_26 = QLabel(self.widget)
                  self.label_26.setObjectName(u"label_26")
                  self.label_26.setFont(font1)
          
                  self.gridLayout.addWidget(self.label_26, 5, 0, 1, 1)
          
                  self.spFlow = QSpinBox(self.widget)
                  self.spFlow.setObjectName(u"spFlow")
                  self.spFlow.setFont(font)
          
                  self.gridLayout.addWidget(self.spFlow, 5, 1, 1, 1)
          
                  self.widget1 = QWidget(Form)
                  self.widget1.setObjectName(u"widget1")
                  self.widget1.setGeometry(QRect(420, 30, 391, 225))
                  self.gridLayout_2 = QGridLayout(self.widget1)
                  self.gridLayout_2.setObjectName(u"gridLayout_2")
                  self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
                  self.label_27 = QLabel(self.widget1)
                  self.label_27.setObjectName(u"label_27")
                  self.label_27.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.label_27, 0, 1, 1, 2)
          
                  self.label_34 = QLabel(self.widget1)
                  self.label_34.setObjectName(u"label_34")
                  self.label_34.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.label_34, 1, 0, 1, 2)
          
                  self.leIP = QLineEdit(self.widget1)
                  self.leIP.setObjectName(u"leIP")
                  self.leIP.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.leIP, 1, 2, 1, 1)
          
                  self.label_29 = QLabel(self.widget1)
                  self.label_29.setObjectName(u"label_29")
                  self.label_29.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.label_29, 2, 0, 1, 1)
          
                  self.lePort = QLineEdit(self.widget1)
                  self.lePort.setObjectName(u"lePort")
                  self.lePort.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.lePort, 2, 2, 1, 1)
          
                  self.label_30 = QLabel(self.widget1)
                  self.label_30.setObjectName(u"label_30")
                  self.label_30.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.label_30, 3, 0, 1, 2)
          
                  self.spUser = QSpinBox(self.widget1)
                  self.spUser.setObjectName(u"spUser")
                  self.spUser.setFont(font)
          
                  self.gridLayout_2.addWidget(self.spUser, 3, 2, 1, 1)
          
                  self.label_31 = QLabel(self.widget1)
                  self.label_31.setObjectName(u"label_31")
                  self.label_31.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.label_31, 4, 0, 1, 1)
          
                  self.spSSID = QSpinBox(self.widget1)
                  self.spSSID.setObjectName(u"spSSID")
                  self.spSSID.setFont(font)
          
                  self.gridLayout_2.addWidget(self.spSSID, 4, 2, 1, 1)
          
                  self.label_32 = QLabel(self.widget1)
                  self.label_32.setObjectName(u"label_32")
                  self.label_32.setFont(font1)
          
                  self.gridLayout_2.addWidget(self.label_32, 5, 0, 1, 2)
          
                  self.spinBox_7 = QSpinBox(self.widget1)
                  self.spinBox_7.setObjectName(u"spinBox_7")
                  self.spinBox_7.setFont(font)
          
                  self.gridLayout_2.addWidget(self.spinBox_7, 5, 2, 1, 1)
          
          
                  self.retranslateUi(Form)
          
                  QMetaObject.connectSlotsByName(Form)
              # setupUi
          
              def retranslateUi(self, Form):
                  Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None))
                  self.label_28.setText(QCoreApplication.translate("Form", u"Wired", None))
                  self.label_35.setText(QCoreApplication.translate("Form", u"COM Port", None))
                  self.label_33.setText(QCoreApplication.translate("Form", u"Baud Rate", None))
                  self.label_24.setText(QCoreApplication.translate("Form", u"Data Bits", None))
                  self.label_25.setText(QCoreApplication.translate("Form", u"Parity", None))
                  self.label_26.setText(QCoreApplication.translate("Form", u"Flow Control", None))
                  self.label_27.setText(QCoreApplication.translate("Form", u"WiFi", None))
                  self.label_34.setText(QCoreApplication.translate("Form", u"IP Address", None))
                  self.label_29.setText(QCoreApplication.translate("Form", u"Port", None))
                  self.label_30.setText(QCoreApplication.translate("Form", u"User Profile", None))
                  self.label_31.setText(QCoreApplication.translate("Form", u"SSID", None))
                  self.label_32.setText(QCoreApplication.translate("Form", u"TextLabel", None))
              # retranslateUi
          
          
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            You are missing a layout for widget and widget1.

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

              You are missing a layout for widget and widget1.

              S Offline
              S Offline
              StephvanS
              wrote on last edited by
              #7

              @SGaist Thank you. I'm still not sure where to put it in the Form Designer.
              The comms.ui file produced by the designers is

              <?xml version="1.0" encoding="UTF-8"?>
              <ui version="4.0">
               <class>Form</class>
               <widget class="QWidget" name="Form">
                <property name="enabled">
                 <bool>true</bool>
                </property>
                <property name="geometry">
                 <rect>
                  <x>0</x>
                  <y>0</y>
                  <width>800</width>
                  <height>400</height>
                 </rect>
                </property>
                <property name="windowTitle">
                 <string>Form</string>
                </property>
                <property name="autoFillBackground">
                 <bool>false</bool>
                </property>
                <widget class="QSlider" name="slComms">
                 <property name="geometry">
                  <rect>
                   <x>300</x>
                   <y>270</y>
                   <width>161</width>
                   <height>16</height>
                  </rect>
                 </property>
                 <property name="font">
                  <font>
                   <pointsize>16</pointsize>
                  </font>
                 </property>
                 <property name="maximum">
                  <number>1</number>
                 </property>
                 <property name="pageStep">
                  <number>1</number>
                 </property>
                 <property name="orientation">
                  <enum>Qt::Horizontal</enum>
                 </property>
                </widget>
                <widget class="QWidget" name="layoutWidget">
                 <property name="geometry">
                  <rect>
                   <x>0</x>
                   <y>30</y>
                   <width>391</width>
                   <height>227</height>
                  </rect>
                 </property>
                 <layout class="QGridLayout" name="gridLayout">
                  <item row="0" column="0" colspan="2">
                   <widget class="QLabel" name="label_28">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>Wired</string>
                    </property>
                   </widget>
                  </item>
                  <item row="1" column="0">
                   <widget class="QLabel" name="label_35">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>COM Port</string>
                    </property>
                   </widget>
                  </item>
                  <item row="1" column="1">
                   <widget class="QSpinBox" name="sbCOM">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="2" column="0">
                   <widget class="QLabel" name="label_33">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>Baud Rate</string>
                    </property>
                   </widget>
                  </item>
                  <item row="2" column="1">
                   <widget class="QSpinBox" name="spBps">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="3" column="0">
                   <widget class="QLabel" name="label_24">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>Data Bits</string>
                    </property>
                   </widget>
                  </item>
                  <item row="3" column="1">
                   <widget class="QSpinBox" name="spBits">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="4" column="0">
                   <widget class="QLabel" name="label_25">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>Parity</string>
                    </property>
                   </widget>
                  </item>
                  <item row="4" column="1">
                   <widget class="QSpinBox" name="spParity">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="5" column="0">
                   <widget class="QLabel" name="label_26">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>Flow Control</string>
                    </property>
                   </widget>
                  </item>
                  <item row="5" column="1">
                   <widget class="QSpinBox" name="spFlow">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                 </layout>
                </widget>
                <widget class="QWidget" name="layoutWidget">
                 <property name="geometry">
                  <rect>
                   <x>420</x>
                   <y>30</y>
                   <width>391</width>
                   <height>225</height>
                  </rect>
                 </property>
                 <layout class="QGridLayout" name="gridLayout_2">
                  <item row="0" column="1" colspan="2">
                   <widget class="QLabel" name="label_27">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>WiFi</string>
                    </property>
                   </widget>
                  </item>
                  <item row="1" column="0" colspan="2">
                   <widget class="QLabel" name="label_34">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>IP Address</string>
                    </property>
                   </widget>
                  </item>
                  <item row="1" column="2">
                   <widget class="QLineEdit" name="leIP">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="2" column="0">
                   <widget class="QLabel" name="label_29">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>Port</string>
                    </property>
                   </widget>
                  </item>
                  <item row="2" column="2">
                   <widget class="QLineEdit" name="lePort">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="3" column="0" colspan="2">
                   <widget class="QLabel" name="label_30">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>User Profile</string>
                    </property>
                   </widget>
                  </item>
                  <item row="3" column="2">
                   <widget class="QSpinBox" name="spUser">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="4" column="0">
                   <widget class="QLabel" name="label_31">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>SSID</string>
                    </property>
                   </widget>
                  </item>
                  <item row="4" column="2">
                   <widget class="QSpinBox" name="spSSID">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                  <item row="5" column="0" colspan="2">
                   <widget class="QLabel" name="label_32">
                    <property name="font">
                     <font>
                      <family>DejaVu Sans</family>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                    <property name="text">
                     <string>TextLabel</string>
                    </property>
                   </widget>
                  </item>
                  <item row="5" column="2">
                   <widget class="QSpinBox" name="spinBox_7">
                    <property name="font">
                     <font>
                      <pointsize>16</pointsize>
                     </font>
                    </property>
                   </widget>
                  </item>
                 </layout>
                </widget>
               </widget>
               <resources/>
               <connections/>
              </ui>
              
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                StephvanS
                wrote on last edited by
                #8

                Ah! starting to see what I missed.
                The initial setLayout right click is only available from the Object Inspector!
                Thank you so much!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  StephvanS
                  wrote on last edited by
                  #9

                  To summarise:
                  The form has to have a "master" layout.
                  This is set as the first step when one creates the form in the ui editor.
                  This is done by right clicking on the form name IN THE OBJECT EXPLORER and selecting "layout".
                  If one right clicks on the form on the designer canvas, the only layout option that's active is "adjust size".
                  So right click on the form in the object explorer, and choose "form layout" or whichever one you need.
                  Thank you to @SGaist !

                  S 1 Reply Last reply
                  0
                  • S StephvanS

                    To summarise:
                    The form has to have a "master" layout.
                    This is set as the first step when one creates the form in the ui editor.
                    This is done by right clicking on the form name IN THE OBJECT EXPLORER and selecting "layout".
                    If one right clicks on the form on the designer canvas, the only layout option that's active is "adjust size".
                    So right click on the form in the object explorer, and choose "form layout" or whichever one you need.
                    Thank you to @SGaist !

                    S Offline
                    S Offline
                    StephvanS
                    wrote on last edited by
                    #10

                    @StephvanS One more question: Only the first tab is rendering the controls. All other tabs are blank.

                    S SGaistS 2 Replies Last reply
                    0
                    • S StephvanS

                      @StephvanS One more question: Only the first tab is rendering the controls. All other tabs are blank.

                      S Offline
                      S Offline
                      StephvanS
                      wrote on last edited by
                      #11

                      @StephvanS Change QDialog main class to QMainWindow and add
                      self.setCentralWidget(self.tabWidget) to the end of the class implementation.

                      1 Reply Last reply
                      0
                      • S StephvanS

                        @StephvanS One more question: Only the first tab is rendering the controls. All other tabs are blank.

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @StephvanS said in Embed form into tab on main window:

                        @StephvanS One more question: Only the first tab is rendering the controls. All other tabs are blank.

                        You only have one tab in your example, are you adding others ?

                        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
                        0

                        • Login

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