
- 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 - QToolBox Widget
The QToolBox is a container widget in PyQt that is used to organize mutiple pages of content just like multiple tabs in a browser. Each page contains a collection of tools or information related to a specific category or topic. QToolBox is often used in applications where the user needs to navigate through diffrent sets of tools or options.
Inheritance
QToolBox inherits its properties from QFrame class which in turn inherits from QWidget class.
Components of QToolBox
There are primarily to main components of QtoolBox −
- Tabs − The tabs are the labelled button present at the top of the widget. Clicking on the tab changes the visible area to specific contetn of the page. This is similar to tabs in browsers.
- Pages − These are individual widgets or layouts that contain application specific functionalities related to the tab level.
Features of QToolBox Widget
- Page-Based Organization − The content of the QToolBox is organized into pages. Each page has a title and respective set of widget and controls.
- Expandable/Collapsible Pages − Pages in QToolBox can be expanded and collapsed to reduce screen-space and provide a clean interface for the user.
- Customizable Appearance − Developers can coustomize the appearence of the QToolBox widget by changing thier style,size and layout of the pages.
- Signal-Slot Mechanism − QToolBox provides signals that can be connected to slots which helps in responding user intercations and change the widget's state.
Methods in QTollBox
Sr.No. | Modules & Description |
---|---|
1 |
addItem() Adds the widget in a new tab at the bottom of the toolbox. |
2 |
count() Counts the number of items contained in the toolbox. |
3 |
currentIndex() Returns the index of the current item. |
4 |
insertItem() Inserts the widget at position index , or at the bottom of the toolbox if index is out of range |
5 |
itemToolTip() Returns the tooltip of the item at a specific index. Returns empty string if the index is out of range. |
6 |
itemText() Returns the text of the item at a specific index or an empty string if the index is out of range.. |
7 |
itemIcon() Returns the icon present in at the specif item index. |
8 |
isItemEnabled() Returns true if the item at specific index is enabled else returns false |
9 |
removeItem() Removes the itme at the specific index from the tooltip. |
10 |
setItemEnabled() If enabled is true then the item at specific index is enabled else the item at specific index is disabled. |
11 |
setItemIcon() Sets the icon of the item at specific index. |
12 |
setItemText() Sets the text of the item at specific index or position. |
Example: Document Viewer with Multiple Tabs
In the below example, we will create a simple document viewer application using Qtoolbox to display multiple document in seperated tabs. We can switch between the documents by selecting different tabs.
import sys from PyQt6.QtWidgets import QApplication, QToolBox, QTextEdit class DocumentViewer(QToolBox): def __init__(self): super().__init__() self.setWindowTitle("Document Viewer") self.document1 = QTextEdit() self.document2 = QTextEdit() self.addItem(self.document1, "Document 1") self.addItem(self.document2, "Document 2") def main(): app = QApplication(sys.argv) viewer = DocumentViewer() viewer.show() sys.exit(app.exec()) if __name__ == "__main__": main()
Output
The above code produces the following output −
