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.

Practice now: Test your Python skills with interactive challenges
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:
toolbox = QToolBox()
After creationg you can add items to the toolbox with the method addItem(). For example:
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).
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
# Add toolbar and items
toolbox = QToolBox()
layout.addWidget(toolbox, 0, 0)
label = QLabel()
toolbox.addItem(label, "Students")
label = QLabel()
toolbox.addItem(label, "Teachers")
label = QLabel()
toolbox.addItem(label, "Directors")
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())
Practice now: Test your Python skills with interactive challenges
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:
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.setLayout(layout)
# Add toolbar and items
toolbox = QToolBox()
layout.addWidget(toolbox, 0, 0)
label = QLabel()
toolbox.addItem(label, "Students")
label = QLabel()
toolbox.addItem(label, "Teachers")
label = QLabel()
toolbox.addItem(label, "Directors")
# show number of items
print(toolbox.count())
# disable tab
toolbox.setItemEnabled(0, False)
# mouseover tooltip
toolbox.setItemToolTip(0, "This is a tooltip")
# tests if items are enabled
print(toolbox.isItemEnabled(0))
print(toolbox.isItemEnabled(1))
# insert item
item = QLabel()
toolbox.insertItem(1, item, "Python")
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())
Practice now: Test your Python skills with interactive challenges
Practice now: Test your Python skills with interactive challenges