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

Download Examples:
Download PyQt examples

QGroupBox

PyQt Groupbox

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

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