
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QGroupBox
A group box is a collection of rectangular frames which controls the labels. These boxes help us to achieve a structured screen design.
The QGroupBox is another widget of group that provides a box frame with a title. It is often used to visually group and organize other widgets within it. The purpose of QGroupBox is to create a container with a title that helps in categorizing and presenting related widgets in a structured manner.
In Layout Management, QGroupBox does not perform any action instead it uses two different layouts- QVBoxLayout or QHBoxLayout. Using these layouts create a group box to arrange the widgets.
In addition to this, we have methods like QPushButton() and addWidgets() that interlink to create a clickable button. It is helpful when the user clicks on any single button.
Example 1
Following example demonstrate the code snippet of QGroupBox using PyQt.
import sys from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QGroupBox, QPushButton class MyWidget(QWidget): def __init__(self): super().__init__() self.init_ui() def init_ui(self): self.setWindowTitle('QGroupBox') self.setGeometry(300, 300, 300, 200) # Create a QVBoxLayout for the main layout main_layout = QVBoxLayout(self) # Create a QGroupBox group_box = QGroupBox('Select your major area of interest-') # Create a layout for the group box group_layout = QVBoxLayout(group_box) # Add widgets to the group box button1 = QPushButton('Python') button2 = QPushButton('Machine Learning') button3 = QPushButton('Deep Learning') button4 = QPushButton('Artificial Intelligence') group_layout.addWidget(button1) group_layout.addWidget(button2) group_layout.addWidget(button3) group_layout.addWidget(button4) # Set the layout of the group box group_box.setLayout(group_layout) # Add the group box to the main layout main_layout.addWidget(group_box) if __name__ == '__main__': app = QApplication(sys.argv) widget = MyWidget() widget.show() sys.exit(app.exec())
Output
The above code produces the following output −

Example 2
Following example demonstrates the set of multiple widgets such as checkboxes, radio buttons, push buttons and enables an option using PyQt.
import sys from PyQt6.QtWidgets import QApplication, QWidget, QGroupBox, QRadioButton, QCheckBox, QPushButton, QMenu, QGridLayout, QVBoxLayout class MyApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): grid = QGridLayout() grid.addWidget(self.createGroupBox('Radio Buttons', ['Radio1', 'Radio2', 'Radio3']), 0, 0) grid.addWidget(self.createGroupBox('Check Boxes', ['Radio1', 'Radio2', 'Radio3'], include_checkbox=True), 1, 0) grid.addWidget(self.createPushButtonGroup(), 1, 1) self.setLayout(grid) self.setWindowTitle('QGroupBox') self.setGeometry(300, 300, 480, 320) self.show() def createGroupBox(self, title, items, include_checkbox=False, is_flat=False, is_tristate=False): groupbox = QGroupBox(title) groupbox.setFlat(is_flat) vbox = QVBoxLayout() for item_text in items: if include_checkbox: widget = QCheckBox(item_text) widget.setTristate(is_tristate) else: widget = QRadioButton(item_text) vbox.addWidget(widget) vbox.addStretch(1) groupbox.setLayout(vbox) return groupbox def createPushButtonGroup(self): groupbox = QGroupBox('Push Buttons') groupbox.setCheckable(True) groupbox.setChecked(True) pushbutton = QPushButton('Normal Button') togglebutton = QPushButton('Toggle Button') togglebutton.setCheckable(True) togglebutton.setChecked(True) flatbutton = QPushButton('Flat Button') flatbutton.setFlat(True) popupbutton = QPushButton('Popup Button') menu = QMenu(self) menu.addActions([menu.addAction(f'Item {i}') for i in range(1, 5)]) popupbutton.setMenu(menu) vbox = QVBoxLayout() vbox.addWidget(pushbutton) vbox.addWidget(togglebutton) vbox.addWidget(flatbutton) vbox.addWidget(popupbutton) vbox.addStretch(1) groupbox.setLayout(vbox) return groupbox if __name__ == '__main__': app = QApplication(sys.argv) ex = MyApp() sys.exit(app.exec())
Output
The above code produces the following output −
