A window can contain widgets (buttons, text field, image and others). Widgets are frequently added to a layout. A horizontal layout can be used to (dynamically) add widgets in horizontal direction.
In this article we’ll show you how to add buttons in the horizontal direction using a horizontal layout.
We start by calling the method self.createHorizontalLayout() inside the initUI() method. Inside the method we create a box with a title and a horizontal layout:
self.horizontalGroupBox = QGroupBox("What is your favorite color?") layout = QHBoxLayout()
We create widgets (in this example QPushButtons) and add them to the layout one by one:
Leave a Reply: