
- 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 - 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 - QToolBar Widget
A QToolBar widget is a movable panel consisting of text buttons, buttons with icons or other widgets.
It is usually situated in a horizontal bar below menu bar, although it can be floating. Some useful methods of QToolBar class are as follows −
Sr.No. | Methods & Description |
---|---|
1 |
addAction() Adds tool buttons having text or icon |
2 |
addSeperator() Shows tool buttons in groups |
3 |
addWidget() Adds controls other than button in the toolbar |
4 |
addToolBar() QMainWindow class method adds a new toolbar |
5 |
setMovable() Toolbar becomes movable |
6 |
setOrientation() Toolbars orientation sets to Qt.Horizontal or Qt.vertical |
Whenever a button on the toolbar is clicked, ActionTriggered() signal is emitted. Additionally, it sends reference to QAction object associated with the event to the connected function.
A File toolbar is added in the toolbar area by calling addToolBar() method.
tb = self.addToolBar("File")
Although tool buttons with text captions can be added, a toolbar usually contains graphic buttons. A QAction object with an icon and name is added to the toolbar.
new = QAction(QIcon("new.bmp"),"new",self) tb.addAction(new)
Similarly, open and save buttons are added.
Finally, actionTriggered() signal is connected to a slot function toolbtnpressed()
tb.actionTriggered[QAction].connect(self.toolbtnpressed)
The complete code to execute the example is as follows −
import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class tooldemo(QMainWindow): def __init__(self, parent = None): super(tooldemo, self).__init__(parent) layout = QVBoxLayout() tb = self.addToolBar("File") new = QAction(QIcon("new.bmp"),"new",self) tb.addAction(new) open = QAction(QIcon("open.bmp"),"open",self) tb.addAction(open) save = QAction(QIcon("save.bmp"),"save",self) tb.addAction(save) tb.actionTriggered[QAction].connect(self.toolbtnpressed) self.setLayout(layout) self.setWindowTitle("toolbar demo") def toolbtnpressed(self,a): print "pressed tool button is",a.text() def main(): app = QApplication(sys.argv) ex = tooldemo() ex.show() sys.exit(app.exec_()) if __name__ == '__main__': main()
The above code produces the following output −
