
- 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 - QScrollArea
The QScrollArea class builds a scrolling view onto another widget. This class is used to display the child widget content within the frame.
In PyQt, we have classes like QScrollArea and QScrollBar that are closely related components and work together to provide scrolling functionality within the application. Both these classes with their methods are useful when we dynamically change the content of the layout.
Methods used in QScrollArea
Building a scroll area require various methods of PyQt −
- QScrollArea() − This method enables the area of content specified.
- QScrollBar() − This method enable the users to scroll the content of the window from left to right or top to bottom.
- setMaximum() − This method is used to set the maximum value of a widgets such as QScrollBar.
- addWidget() − This add widget to grid layout.
- setGeometry() − This method is used to set the geometry for PyQt application such as left, top, width, and height.
- addrow() − This adds the number of widgets in row wise.
- setWidget() − Set the widget as the content of the scroll area using setWidget().
Advantages of QScrollArea
- This is esssential for navigating the lengthy content such as webpages, documents, and lists.
- Using ScrollArea you can get the portion of length as per any given topic.
- ScrollArea uses the various properties such as label, bars, grids, and general attributes.
- It controls all the scrollable data.
Example 1
Following example demonstrate the vertical scrollbar in PyQt window application.
import sys from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QListWidget, QScrollBar class Window(QWidget): def __init__(self): super().__init__() self.MyUI() def MyUI(self): # Create a QListWidget to display the items self.list_widget = QListWidget(self) # Add some items to the list for i in range(20): self.list_widget.addItem("Item {}".format(i)) # Create a scrollbar and connect it to the list scrollbar = QScrollBar(self) scrollbar.setMaximum(self.list_widget.count()) scrollbar.sliderMoved.connect(self.list_widget.setCurrentRow) # Create a layout for the widget and add the list and scrollbar to it vbox = QVBoxLayout(self) vbox.addWidget(self.list_widget) vbox.addWidget(scrollbar) self.setLayout(vbox) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('PyQt(Scrollbar)') self.show() if __name__ == '__main__': app = QApplication(sys.argv) window = Window() sys.exit(app.exec())
Output
The above code produces the following output−

Example 2
Following example illustrate the multiple rows of push button using for-loop and display the area of scollbar using QScrollArea and it's relevant method.
import sys from PyQt6 import QtGui from PyQt6.QtWidgets import QApplication, QWidget, QScrollArea, QVBoxLayout, QGroupBox, QLabel, QPushButton, QFormLayout class Window(QWidget): def __init__(self, val): super().__init__() self.title = "Scroll Bar" self.top = 200 self.left = 500 self.width = 400 self.height = 300 self.setWindowIcon(QtGui.QIcon("icon.png")) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) formLayout =QFormLayout() groupBox = QGroupBox("This Is Group Box") labelLis = [] comboList = [] for i in range(val): labelLis.append(QLabel("Label")) comboList.append(QPushButton("Click Me")) formLayout.addRow(labelLis[i], comboList[i]) groupBox.setLayout(formLayout) scroll = QScrollArea() scroll.setWidget(groupBox) scroll.setWidgetResizable(True) scroll.setFixedHeight(400) layout = QVBoxLayout(self) layout.addWidget(scroll) self.show() App = QApplication(sys.argv) window = Window(30) sys.exit(App.exec())
Output
The above code produces the following output−
