from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QLabel, QWidget app = QApplication([]) window = QWidget() label = QLabel("Hello World") label.setSizePolicy(Qt.QSizePolicy.Expanding, Qt.QSizePolicy.Expanding) window.setLayout(QVBoxLayout()) window.layout().addWidget(label) window.show() app.exec_()
from qgis.PyQt.QtWidgets import QApplication, QLabel, QWidget app = QApplication([]) window = QWidget() label = QLabel("Hello World") label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) window.setLayout(QVBoxLayout()) window.layout().addWidget(label) window.show() app.exec_()In this example, we create a QLabel widget with some text and set its size policy to be expanding in both directions. The main difference is that instead of importing Qt from PyQt5, we import it from qgis.PyQt, which is the package library for QGIS. QGIS uses PyQt as its GUI toolkit, and so this allows us to use the QLabel widget within the QGIS environment.