Toolbox (QToolBox) is a container widget in PyQt. The widget can show groups of items separated by tabs. If there are to many items for a toolbar, you may want a toolbox.
A screenshot of a toolbox QToolBox
is shown below.
Related Course: Create GUI Apps with Python PyQt5
Toolbox example
QToolBox
A QToolBox widget shows a column of tabs one above the other. The current item is shown below the current tab. Every tab has an index position and every tab’s item is a QWidget. A toolbox (QToolBox) can be created with a single line of code:
1 | toolbox = QToolBox() |
After creationg you can add items to the toolbox with the method addItem(). For example:
1 | toolbox.addItem(label, "Students") |
The Python code below creates a toolbox with 3 items. The toolbox QToolBox
has a method .addItem()
, which is used to add it ems.
The toolbox itself has to be added to a layout, for instance layout.addWidget(toolbox, 0, 0)
.
1 | from PyQt5.QtWidgets import * |
Methods
The QToolBox has many methods that can be used, you’ve seen .addItem() before but there are many more.
- addItem()
- count()
- currentIndex()
- insertItem()
- itemToolTip()
- itemText()
- itemIcon()
- isItemEnabled()
- removeItem()
- setItemEnabled()
- setItemIcon()
- setItemText()
- setItemToolTip()
The example below demonstrates the use of some of these methods:
1 | from PyQt5.QtWidgets import * |
If you are new to Python PyQt, then I highly recommend this book.