How to change the position of labels, line edits, etc relative to the window size?












1














I am creating a GUI app. All the windows in the app contain line edits, buttons, etc. I want the position of those to change relative to the window size, while the application is in use. The position of those should change if the user maximizes or alters the window size.



The code is as follows:



from PyQt5 import QtCore, QtGui, QtWidgets

class MainWindow(object):

def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1125, 969)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(350, 330, 361, 81))
font = QtGui.QFont()
font.setPointSize(24)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(470, 510, 75, 51))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1125, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")

MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Window"))
self.label.setText(_translate("MainWindow", " Manager"))
self.pushButton.setText(_translate("MainWindow", "Lets Start!"))


if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
main_window = QtWidgets.QMainWindow()
ui = MainWindow()
ui.setupUi(main_window)
main_window.show()
sys.exit(app.exec_())









share|improve this question




















  • 2




    Use the designer and layouts together with spacers.
    – deets
    Nov 20 '18 at 15:46






  • 1




    How do you want your window to look with different sizes?
    – eyllanesc
    Nov 20 '18 at 15:46










  • @eyllanesc For example, I have given the initial position of the label (approx in the middle of the window). So, while the user changes the window size, I want the position of the label to automatically get adjusted to the center.
    – M. Denis
    Nov 20 '18 at 15:50






  • 1




    @M.Denis and the button?
    – eyllanesc
    Nov 20 '18 at 15:51










  • @eyllanesc yeah the button as well. I guess the solution for labels will fit for buttons.
    – M. Denis
    Nov 20 '18 at 15:53
















1














I am creating a GUI app. All the windows in the app contain line edits, buttons, etc. I want the position of those to change relative to the window size, while the application is in use. The position of those should change if the user maximizes or alters the window size.



The code is as follows:



from PyQt5 import QtCore, QtGui, QtWidgets

class MainWindow(object):

def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1125, 969)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(350, 330, 361, 81))
font = QtGui.QFont()
font.setPointSize(24)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(470, 510, 75, 51))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1125, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")

MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Window"))
self.label.setText(_translate("MainWindow", " Manager"))
self.pushButton.setText(_translate("MainWindow", "Lets Start!"))


if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
main_window = QtWidgets.QMainWindow()
ui = MainWindow()
ui.setupUi(main_window)
main_window.show()
sys.exit(app.exec_())









share|improve this question




















  • 2




    Use the designer and layouts together with spacers.
    – deets
    Nov 20 '18 at 15:46






  • 1




    How do you want your window to look with different sizes?
    – eyllanesc
    Nov 20 '18 at 15:46










  • @eyllanesc For example, I have given the initial position of the label (approx in the middle of the window). So, while the user changes the window size, I want the position of the label to automatically get adjusted to the center.
    – M. Denis
    Nov 20 '18 at 15:50






  • 1




    @M.Denis and the button?
    – eyllanesc
    Nov 20 '18 at 15:51










  • @eyllanesc yeah the button as well. I guess the solution for labels will fit for buttons.
    – M. Denis
    Nov 20 '18 at 15:53














1












1








1







I am creating a GUI app. All the windows in the app contain line edits, buttons, etc. I want the position of those to change relative to the window size, while the application is in use. The position of those should change if the user maximizes or alters the window size.



The code is as follows:



from PyQt5 import QtCore, QtGui, QtWidgets

class MainWindow(object):

def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1125, 969)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(350, 330, 361, 81))
font = QtGui.QFont()
font.setPointSize(24)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(470, 510, 75, 51))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1125, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")

MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Window"))
self.label.setText(_translate("MainWindow", " Manager"))
self.pushButton.setText(_translate("MainWindow", "Lets Start!"))


if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
main_window = QtWidgets.QMainWindow()
ui = MainWindow()
ui.setupUi(main_window)
main_window.show()
sys.exit(app.exec_())









share|improve this question















I am creating a GUI app. All the windows in the app contain line edits, buttons, etc. I want the position of those to change relative to the window size, while the application is in use. The position of those should change if the user maximizes or alters the window size.



The code is as follows:



from PyQt5 import QtCore, QtGui, QtWidgets

class MainWindow(object):

def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1125, 969)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(350, 330, 361, 81))
font = QtGui.QFont()
font.setPointSize(24)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(470, 510, 75, 51))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1125, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")

MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Window"))
self.label.setText(_translate("MainWindow", " Manager"))
self.pushButton.setText(_translate("MainWindow", "Lets Start!"))


if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
main_window = QtWidgets.QMainWindow()
ui = MainWindow()
ui.setupUi(main_window)
main_window.show()
sys.exit(app.exec_())






python pyqt pyqt5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 15:44









eyllanesc

75.2k103156




75.2k103156










asked Nov 20 '18 at 15:42









M. DenisM. Denis

528




528








  • 2




    Use the designer and layouts together with spacers.
    – deets
    Nov 20 '18 at 15:46






  • 1




    How do you want your window to look with different sizes?
    – eyllanesc
    Nov 20 '18 at 15:46










  • @eyllanesc For example, I have given the initial position of the label (approx in the middle of the window). So, while the user changes the window size, I want the position of the label to automatically get adjusted to the center.
    – M. Denis
    Nov 20 '18 at 15:50






  • 1




    @M.Denis and the button?
    – eyllanesc
    Nov 20 '18 at 15:51










  • @eyllanesc yeah the button as well. I guess the solution for labels will fit for buttons.
    – M. Denis
    Nov 20 '18 at 15:53














  • 2




    Use the designer and layouts together with spacers.
    – deets
    Nov 20 '18 at 15:46






  • 1




    How do you want your window to look with different sizes?
    – eyllanesc
    Nov 20 '18 at 15:46










  • @eyllanesc For example, I have given the initial position of the label (approx in the middle of the window). So, while the user changes the window size, I want the position of the label to automatically get adjusted to the center.
    – M. Denis
    Nov 20 '18 at 15:50






  • 1




    @M.Denis and the button?
    – eyllanesc
    Nov 20 '18 at 15:51










  • @eyllanesc yeah the button as well. I guess the solution for labels will fit for buttons.
    – M. Denis
    Nov 20 '18 at 15:53








2




2




Use the designer and layouts together with spacers.
– deets
Nov 20 '18 at 15:46




Use the designer and layouts together with spacers.
– deets
Nov 20 '18 at 15:46




1




1




How do you want your window to look with different sizes?
– eyllanesc
Nov 20 '18 at 15:46




How do you want your window to look with different sizes?
– eyllanesc
Nov 20 '18 at 15:46












@eyllanesc For example, I have given the initial position of the label (approx in the middle of the window). So, while the user changes the window size, I want the position of the label to automatically get adjusted to the center.
– M. Denis
Nov 20 '18 at 15:50




@eyllanesc For example, I have given the initial position of the label (approx in the middle of the window). So, while the user changes the window size, I want the position of the label to automatically get adjusted to the center.
– M. Denis
Nov 20 '18 at 15:50




1




1




@M.Denis and the button?
– eyllanesc
Nov 20 '18 at 15:51




@M.Denis and the button?
– eyllanesc
Nov 20 '18 at 15:51












@eyllanesc yeah the button as well. I guess the solution for labels will fit for buttons.
– M. Denis
Nov 20 '18 at 15:53




@eyllanesc yeah the button as well. I guess the solution for labels will fit for buttons.
– M. Denis
Nov 20 '18 at 15:53












1 Answer
1






active

oldest

votes


















2














Since you are using Qt Designer I will offer a solution using that tool, for this you can use the following scheme:



QMainWindow
└── QHBoxLayout
├── QSpacerItem
├── QVBoxLayout
│   ├── QSpacerItem
│   ├── QLabel
│   ├── QPushButton
│   └── QSpacerItem
└── QSpacerItem


Getting the following .ui:



<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<height>179</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>129</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>128</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>24</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Manager</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Lets Start!</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>128</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>128</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<height>24</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>


enter image description here



and then convert it to .py with pyuic.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396564%2fhow-to-change-the-position-of-labels-line-edits-etc-relative-to-the-window-siz%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Since you are using Qt Designer I will offer a solution using that tool, for this you can use the following scheme:



    QMainWindow
    └── QHBoxLayout
    ├── QSpacerItem
    ├── QVBoxLayout
    │   ├── QSpacerItem
    │   ├── QLabel
    │   ├── QPushButton
    │   └── QSpacerItem
    └── QSpacerItem


    Getting the following .ui:



    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>424</width>
    <height>179</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralwidget">
    <layout class="QHBoxLayout" name="horizontalLayout">
    <item>
    <spacer name="horizontalSpacer">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>129</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    <item>
    <layout class="QVBoxLayout" name="verticalLayout">
    <item>
    <spacer name="verticalSpacer">
    <property name="orientation">
    <enum>Qt::Vertical</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>128</width>
    <height>13</height>
    </size>
    </property>
    </spacer>
    </item>
    <item>
    <widget class="QLabel" name="label">
    <property name="font">
    <font>
    <pointsize>24</pointsize>
    <weight>75</weight>
    <bold>true</bold>
    </font>
    </property>
    <property name="text">
    <string>Manager</string>
    </property>
    <property name="alignment">
    <set>Qt::AlignCenter</set>
    </property>
    </widget>
    </item>
    <item>
    <widget class="QPushButton" name="pushButton">
    <property name="text">
    <string>Lets Start!</string>
    </property>
    </widget>
    </item>
    <item>
    <spacer name="verticalSpacer_2">
    <property name="orientation">
    <enum>Qt::Vertical</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>128</width>
    <height>13</height>
    </size>
    </property>
    </spacer>
    </item>
    </layout>
    </item>
    <item>
    <spacer name="horizontalSpacer_2">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>128</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    </layout>
    </widget>
    <widget class="QMenuBar" name="menubar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>424</width>
    <height>24</height>
    </rect>
    </property>
    </widget>
    <widget class="QStatusBar" name="statusbar"/>
    </widget>
    <resources/>
    <connections/>
    </ui>


    enter image description here



    and then convert it to .py with pyuic.






    share|improve this answer


























      2














      Since you are using Qt Designer I will offer a solution using that tool, for this you can use the following scheme:



      QMainWindow
      └── QHBoxLayout
      ├── QSpacerItem
      ├── QVBoxLayout
      │   ├── QSpacerItem
      │   ├── QLabel
      │   ├── QPushButton
      │   └── QSpacerItem
      └── QSpacerItem


      Getting the following .ui:



      <?xml version="1.0" encoding="UTF-8"?>
      <ui version="4.0">
      <class>MainWindow</class>
      <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
      <rect>
      <x>0</x>
      <y>0</y>
      <width>424</width>
      <height>179</height>
      </rect>
      </property>
      <property name="windowTitle">
      <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralwidget">
      <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
      <spacer name="horizontalSpacer">
      <property name="orientation">
      <enum>Qt::Horizontal</enum>
      </property>
      <property name="sizeHint" stdset="0">
      <size>
      <width>129</width>
      <height>20</height>
      </size>
      </property>
      </spacer>
      </item>
      <item>
      <layout class="QVBoxLayout" name="verticalLayout">
      <item>
      <spacer name="verticalSpacer">
      <property name="orientation">
      <enum>Qt::Vertical</enum>
      </property>
      <property name="sizeHint" stdset="0">
      <size>
      <width>128</width>
      <height>13</height>
      </size>
      </property>
      </spacer>
      </item>
      <item>
      <widget class="QLabel" name="label">
      <property name="font">
      <font>
      <pointsize>24</pointsize>
      <weight>75</weight>
      <bold>true</bold>
      </font>
      </property>
      <property name="text">
      <string>Manager</string>
      </property>
      <property name="alignment">
      <set>Qt::AlignCenter</set>
      </property>
      </widget>
      </item>
      <item>
      <widget class="QPushButton" name="pushButton">
      <property name="text">
      <string>Lets Start!</string>
      </property>
      </widget>
      </item>
      <item>
      <spacer name="verticalSpacer_2">
      <property name="orientation">
      <enum>Qt::Vertical</enum>
      </property>
      <property name="sizeHint" stdset="0">
      <size>
      <width>128</width>
      <height>13</height>
      </size>
      </property>
      </spacer>
      </item>
      </layout>
      </item>
      <item>
      <spacer name="horizontalSpacer_2">
      <property name="orientation">
      <enum>Qt::Horizontal</enum>
      </property>
      <property name="sizeHint" stdset="0">
      <size>
      <width>128</width>
      <height>20</height>
      </size>
      </property>
      </spacer>
      </item>
      </layout>
      </widget>
      <widget class="QMenuBar" name="menubar">
      <property name="geometry">
      <rect>
      <x>0</x>
      <y>0</y>
      <width>424</width>
      <height>24</height>
      </rect>
      </property>
      </widget>
      <widget class="QStatusBar" name="statusbar"/>
      </widget>
      <resources/>
      <connections/>
      </ui>


      enter image description here



      and then convert it to .py with pyuic.






      share|improve this answer
























        2












        2








        2






        Since you are using Qt Designer I will offer a solution using that tool, for this you can use the following scheme:



        QMainWindow
        └── QHBoxLayout
        ├── QSpacerItem
        ├── QVBoxLayout
        │   ├── QSpacerItem
        │   ├── QLabel
        │   ├── QPushButton
        │   └── QSpacerItem
        └── QSpacerItem


        Getting the following .ui:



        <?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0">
        <class>MainWindow</class>
        <widget class="QMainWindow" name="MainWindow">
        <property name="geometry">
        <rect>
        <x>0</x>
        <y>0</y>
        <width>424</width>
        <height>179</height>
        </rect>
        </property>
        <property name="windowTitle">
        <string>MainWindow</string>
        </property>
        <widget class="QWidget" name="centralwidget">
        <layout class="QHBoxLayout" name="horizontalLayout">
        <item>
        <spacer name="horizontalSpacer">
        <property name="orientation">
        <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>129</width>
        <height>20</height>
        </size>
        </property>
        </spacer>
        </item>
        <item>
        <layout class="QVBoxLayout" name="verticalLayout">
        <item>
        <spacer name="verticalSpacer">
        <property name="orientation">
        <enum>Qt::Vertical</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>128</width>
        <height>13</height>
        </size>
        </property>
        </spacer>
        </item>
        <item>
        <widget class="QLabel" name="label">
        <property name="font">
        <font>
        <pointsize>24</pointsize>
        <weight>75</weight>
        <bold>true</bold>
        </font>
        </property>
        <property name="text">
        <string>Manager</string>
        </property>
        <property name="alignment">
        <set>Qt::AlignCenter</set>
        </property>
        </widget>
        </item>
        <item>
        <widget class="QPushButton" name="pushButton">
        <property name="text">
        <string>Lets Start!</string>
        </property>
        </widget>
        </item>
        <item>
        <spacer name="verticalSpacer_2">
        <property name="orientation">
        <enum>Qt::Vertical</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>128</width>
        <height>13</height>
        </size>
        </property>
        </spacer>
        </item>
        </layout>
        </item>
        <item>
        <spacer name="horizontalSpacer_2">
        <property name="orientation">
        <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>128</width>
        <height>20</height>
        </size>
        </property>
        </spacer>
        </item>
        </layout>
        </widget>
        <widget class="QMenuBar" name="menubar">
        <property name="geometry">
        <rect>
        <x>0</x>
        <y>0</y>
        <width>424</width>
        <height>24</height>
        </rect>
        </property>
        </widget>
        <widget class="QStatusBar" name="statusbar"/>
        </widget>
        <resources/>
        <connections/>
        </ui>


        enter image description here



        and then convert it to .py with pyuic.






        share|improve this answer












        Since you are using Qt Designer I will offer a solution using that tool, for this you can use the following scheme:



        QMainWindow
        └── QHBoxLayout
        ├── QSpacerItem
        ├── QVBoxLayout
        │   ├── QSpacerItem
        │   ├── QLabel
        │   ├── QPushButton
        │   └── QSpacerItem
        └── QSpacerItem


        Getting the following .ui:



        <?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0">
        <class>MainWindow</class>
        <widget class="QMainWindow" name="MainWindow">
        <property name="geometry">
        <rect>
        <x>0</x>
        <y>0</y>
        <width>424</width>
        <height>179</height>
        </rect>
        </property>
        <property name="windowTitle">
        <string>MainWindow</string>
        </property>
        <widget class="QWidget" name="centralwidget">
        <layout class="QHBoxLayout" name="horizontalLayout">
        <item>
        <spacer name="horizontalSpacer">
        <property name="orientation">
        <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>129</width>
        <height>20</height>
        </size>
        </property>
        </spacer>
        </item>
        <item>
        <layout class="QVBoxLayout" name="verticalLayout">
        <item>
        <spacer name="verticalSpacer">
        <property name="orientation">
        <enum>Qt::Vertical</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>128</width>
        <height>13</height>
        </size>
        </property>
        </spacer>
        </item>
        <item>
        <widget class="QLabel" name="label">
        <property name="font">
        <font>
        <pointsize>24</pointsize>
        <weight>75</weight>
        <bold>true</bold>
        </font>
        </property>
        <property name="text">
        <string>Manager</string>
        </property>
        <property name="alignment">
        <set>Qt::AlignCenter</set>
        </property>
        </widget>
        </item>
        <item>
        <widget class="QPushButton" name="pushButton">
        <property name="text">
        <string>Lets Start!</string>
        </property>
        </widget>
        </item>
        <item>
        <spacer name="verticalSpacer_2">
        <property name="orientation">
        <enum>Qt::Vertical</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>128</width>
        <height>13</height>
        </size>
        </property>
        </spacer>
        </item>
        </layout>
        </item>
        <item>
        <spacer name="horizontalSpacer_2">
        <property name="orientation">
        <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
        <size>
        <width>128</width>
        <height>20</height>
        </size>
        </property>
        </spacer>
        </item>
        </layout>
        </widget>
        <widget class="QMenuBar" name="menubar">
        <property name="geometry">
        <rect>
        <x>0</x>
        <y>0</y>
        <width>424</width>
        <height>24</height>
        </rect>
        </property>
        </widget>
        <widget class="QStatusBar" name="statusbar"/>
        </widget>
        <resources/>
        <connections/>
        </ui>


        enter image description here



        and then convert it to .py with pyuic.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 16:08









        eyllanesceyllanesc

        75.2k103156




        75.2k103156






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396564%2fhow-to-change-the-position-of-labels-line-edits-etc-relative-to-the-window-siz%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy