A groupbox QGroupBox can group widgets. It typically has a title and a border. Any widget can be added into the group box. This can be further used to communciate your UI/UX to your user.

This example demonstrates how to create the groupbox as shown below:

pyqt groupbox

Related Course:
PyQt Desktop Apps with Python
icon

QGroupBox

PyQt Groupbox

The groupbox is initialized with QGroupBox("title"). A layout is then added to the groupbox. Widgets are added to the layout.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from PyQt5.QtWidgets import *
import sys

class GroupBox(QWidget):

def __init__(self):
QWidget.__init__(self)

self.setWindowTitle("GroupBox")
layout = QGridLayout()
self.setLayout(layout)

groupbox = QGroupBox("GroupBox Example")
groupbox.setCheckable(True)
layout.addWidget(groupbox)

vbox = QVBoxLayout()
groupbox.setLayout(vbox)

radiobutton = QRadioButton("RadioButton 1")
vbox.addWidget(radiobutton)

radiobutton = QRadioButton("RadioButton 2")
vbox.addWidget(radiobutton)

radiobutton = QRadioButton("RadioButton 3")
vbox.addWidget(radiobutton)

radiobutton = QRadioButton("RadioButton 4")
vbox.addWidget(radiobutton)


app = QApplication(sys.argv)
screen = GroupBox()
screen.show()
sys.exit(app.exec_())