PyQt5 absolute position

PyQt5 supports several layout methods such as grid layouts, horzontal layous and absolute positioning. The layout you should pick depends on your preference and type of application.

Related course:
Create Simple GUI Applications with Python and Qt

PyQt5 absolute positioning

Absolute positioning gives you total control over the widget positions but you have to explicitly define every widget location.

Widgets can be added on an absolute position using the move(x,y) method.


PyQt5 absolute positioning

PyQt5 widget positioning example

The example below puts widgets on the absolute positions using the move() method.
They are added to a PyQT5 window (QMainWindow) which has some properties set in initUI().

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel
from PyQt5.QtGui import QIcon
class App(QMainWindow):
    def __init__(self):
        self.title = 'PyQt absolute positioning -'
        self.left = 10 = 10
        self.width = 440
        self.height = 280
    def initUI(self):
        self.setGeometry(self.left,, self.width, self.height)
        label = QLabel('Python', self)
        label2 = QLabel('PyQt5', self)
        label3 = QLabel('Examples', self)
        label4 = QLabel('', self)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
PyQt5 textbox example
PyQt5 menu
This entry was posted in PyQt5 and tagged . Bookmark the permalink.