python logo

PyQt5 absolute position

Python hosting: Host, run, and code Python in the cloud!

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 GUI Apps with PyQt5

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-position 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()

If you are new to programming Python PyQt, I highly recommend this book.

Download PyQT5 Examples


Leave a Reply: