Simply enough, I want to add two labels inside an horizontal box layout using Python's PYQT5.
When I execute this code, the two labels appear on top of each other, even though adding them to a QHBoxLayout should position them from left to right.
How can I fix this?
- Compiler : Python 3.7.4 32 bit
- IDE : Visual Studio Code
- OS : Windows 10
my code:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Interface(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'debug'
self.mainLayout = QHBoxLayout()
self.initGUI()
def initGUI(self):
self.setGeometry(0,0,200,200)
self.setFixedSize(self.size())
self.setWindowTitle(self.title)
label1 = QLabel('test 1',self)
label2 = QLabel('test 2',self)
self.mainLayout.addWidget(label1)
self.mainLayout.addWidget(label2)
self.setLayout(self.mainLayout)
self.show()
def close_application(self):
sys.exit()
if __name__ == '__main__':
app = QApplication([])
window = Interface()
sys.exit(app.exec_())