Results 1 to 2 of 2

Thread: adding another widget to an existing widget

  1. #1
    Join Date
    Jan 2020
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default adding another widget to an existing widget

    i have created two widgets and im now trying to add them together my code will be displayed below, im using python and qt. Im stuck can anyone help?

    from PySide2 import QtCore, QtGui, QtWidgets

    class Ui_MainWindow(object):


    def setupUi(self, MainWindow):
    MainWindow.setObjectName("MainWindow")
    MainWindow.resize(939, 480)
    MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);")
    self.centralWidget = QtWidgets.QWidget(MainWindow)
    self.centralWidget.setStyleSheet("QPushButton{\n"
    "background-color: rgb(255, 255, 255);\n"
    "border: 1px solid grey;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "background-color:rgb(200, 200, 200);\n"
    "}\n"
    "\n"
    "QPushButtonressed {\n"
    " background-color: grey;\n"
    "}")
    self.centralWidget.setObjectName("centralWidget")
    self.verticalLayout = QtWidgets.QVBoxLayout(self.centralWidget)
    self.verticalLayout.setSpacing(0)
    self.verticalLayout.setContentsMargins(0, 0, 0, 0)
    self.verticalLayout.setObjectName("verticalLayout" )
    self.splitter_2 = QtWidgets.QSplitter(self.centralWidget)
    self.splitter_2.setOrientation(QtCore.Qt.Horizonta l)
    self.splitter_2.setObjectName("splitter_2")
    self.Jodies_Widget = QtWidgets.QWidget(self.splitter_2)
    sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Prefer red, QtWidgets.QSizePolicy.Preferred)
    sizePolicy.setHorizontalStretch(0)
    sizePolicy.setVerticalStretch(0)
    sizePolicy.setHeightForWidth(self.Jodies_Widget.si zePolicy().hasHeightForWidth())
    self.Jodies_Widget.setSizePolicy(sizePolicy)
    self.Jodies_Widget.setMinimumSize(QtCore.QSize(200 , 100))
    self.Jodies_Widget.setStyleSheet("background-color: rgb(200, 200, 200);\n"
    "border: 3px solid grey;")
    self.Jodies_Widget.setObjectName("Jodie Widget")

    self.tabWidget = QtWidgets.QTabWidget(self.splitter_2)
    sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expand ing, QtWidgets.QSizePolicy.Expanding)
    sizePolicy.setHorizontalStretch(0)
    sizePolicy.setVerticalStretch(0)
    sizePolicy.setHeightForWidth(self.tabWidget.sizePo licy().hasHeightForWidth())
    self.tabWidget.setSizePolicy(sizePolicy)
    self.tabWidget.setMinimumSize(QtCore.QSize(0, 0))
    self.tabWidget.setStyleSheet("")
    self.tabWidget.setTabBarAutoHide(False)
    self.tabWidget.setObjectName("tabWidget")
    self.tab_1 = QtWidgets.QWidget()
    self.tab_1.setObjectName("tab_1")
    self.gridLayout = QtWidgets.QGridLayout(self.tab_1)
    self.gridLayout.setObjectName("gridLayout")
    self.verticalLayout_2 = QtWidgets.QVBoxLayout()
    self.verticalLayout_2.setObjectName("verticalLayou t_2")
    self.label_33 = QtWidgets.QLabel(self.tab_1)
    self.label_33.setStyleSheet("")
    self.label_33.setObjectName("label_33")
    self.verticalLayout_2.addWidget(self.label_33)
    self.label_34 = QtWidgets.QLabel(self.tab_1)
    self.label_34.setObjectName("label_34")
    self.verticalLayout_2.addWidget(self.label_34)
    self.gridLayout.addLayout(self.verticalLayout_2, 1, 1, 1, 1)
    spacerItem = QtWidgets.QSpacerItem(274, 156, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
    self.gridLayout.addItem(spacerItem, 0, 1, 1, 1)
    spacerItem1 = QtWidgets.QSpacerItem(147, 44, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
    self.gridLayout.addItem(spacerItem1, 1, 0, 1, 1)
    spacerItem2 = QtWidgets.QSpacerItem(146, 44, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
    self.gridLayout.addItem(spacerItem2, 1, 2, 1, 1)
    spacerItem3 = QtWidgets.QSpacerItem(274, 156, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
    self.gridLayout.addItem(spacerItem3, 2, 1, 1, 1)
    self.tabWidget.addTab(self.tab_1, "")
    self.tab_2 = QtWidgets.QWidget()
    self.tab_2.setObjectName("tab_2")
    self.gridLayout_2 = QtWidgets.QGridLayout(self.tab_2)
    self.gridLayout_2.setObjectName("gridLayout_2")
    self.splitter = QtWidgets.QSplitter(self.tab_2)
    self.splitter.setOrientation(QtCore.Qt.Vertical)
    self.splitter.setObjectName("splitter")
    self.layoutWidget = QtWidgets.QWidget(self.splitter)
    self.layoutWidget.setObjectName("layoutWidget")
    self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.layoutWidget)
    self.horizontalLayout_8.setContentsMargins(0, 0, 0, 0)
    self.horizontalLayout_8.setObjectName("horizontalL ayout_8")
    spacerItem4 = QtWidgets.QSpacerItem(31, 19, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
    self.horizontalLayout_8.addItem(spacerItem4)
    self.label_35 = QtWidgets.QLabel(self.layoutWidget)
    self.label_35.setStyleSheet("")

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,589
    Thanks
    13
    Thanked 1,585 Times in 1,514 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: adding another widget to an existing widget

    You have not really explained what you expected and what you got... or which "two widgets" you are taking about.

    It looks like you have been using Designer to get a *.ui file and compiling it with pyuic. Correct?

    You can use Designer to compose the two widgets (whichever they are) and then generate the code from the resulting UI file. Alternatively, build two completely independent widgets using Designer and manually code composing them into a parent layout. Generally, if the preview in Designer does not look right then the code generated probably will not either. Does this look correct in Designer?

Similar Threads

  1. Adding widget to bottom left corned of existing Widget
    By carobnodrvo in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2016, 09:19
  2. Add widget on top of existing QGLWidget
    By scarecr0w132 in forum Qt Programming
    Replies: 0
    Last Post: 6th December 2013, 01:18
  3. Replies: 1
    Last Post: 3rd December 2010, 14:02
  4. Adding custom widget to an existing layout
    By santana in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2010, 18:29
  5. Designer: How to promote to a existing Qt Widget?
    By nightghost in forum Qt Programming
    Replies: 2
    Last Post: 9th December 2009, 10:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.