QToolBar Class
The QToolBar class provides a movable panel that contains a set of controls. More...
Header: | #include <QToolBar> |
qmake: | QT += widgets |
Inherits: | QWidget. |
Properties
|
|
Public Functions
QToolBar(const QString & title, QWidget * parent = 0) | |
QToolBar(QWidget * parent = 0) | |
~QToolBar() | |
QAction * | actionAt(const QPoint & p) const |
QAction * | actionAt(int x, int y) const |
void | addAction(QAction * action) |
QAction * | addAction(const QString & text) |
QAction * | addAction(const QIcon & icon, const QString & text) |
QAction * | addAction(const QString & text, const QObject * receiver, const char * member) |
QAction * | addAction(const QIcon & icon, const QString & text, const QObject * receiver, const char * member) |
QAction * | addSeparator() |
QAction * | addWidget(QWidget * widget) |
Qt::ToolBarAreas | allowedAreas() const |
void | clear() |
QSize | iconSize() const |
QAction * | insertSeparator(QAction * before) |
QAction * | insertWidget(QAction * before, QWidget * widget) |
bool | isAreaAllowed(Qt::ToolBarArea area) const |
bool | isFloatable() const |
bool | isFloating() const |
bool | isMovable() const |
Qt::Orientation | orientation() const |
void | setAllowedAreas(Qt::ToolBarAreas areas) |
void | setFloatable(bool floatable) |
void | setMovable(bool movable) |
void | setOrientation(Qt::Orientation orientation) |
QAction * | toggleViewAction() const |
Qt::ToolButtonStyle | toolButtonStyle() const |
QWidget * | widgetForAction(QAction * action) const |
- 217 public functions inherited from QWidget
- 31 public functions inherited from QObject
- 13 public functions inherited from QPaintDevice
Public Slots
void | setIconSize(const QSize & iconSize) |
void | setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle) |
Signals
void | actionTriggered(QAction * action) |
void | allowedAreasChanged(Qt::ToolBarAreas allowedAreas) |
void | iconSizeChanged(const QSize & iconSize) |
void | movableChanged(bool movable) |
void | orientationChanged(Qt::Orientation orientation) |
void | toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle) |
void | topLevelChanged(bool topLevel) |
void | visibilityChanged(bool visible) |
Reimplemented Protected Functions
virtual void | actionEvent(QActionEvent * event) |
virtual void | changeEvent(QEvent * event) |
virtual bool | event(QEvent * event) |
virtual void | paintEvent(QPaintEvent * event) |
- 37 protected functions inherited from QWidget
- 9 protected functions inherited from QObject
- 1 protected function inherited from QPaintDevice
Additional Inherited Members
- 5 static public members inherited from QWidget
- 11 static public members inherited from QObject
- 37 protected functions inherited from QWidget
- 9 protected functions inherited from QObject
- 1 protected function inherited from QPaintDevice
- 1 protected slot inherited from QWidget
Detailed Description
The QToolBar class provides a movable panel that contains a set of controls.
Toolbar buttons are added by adding actions, using addAction() or insertAction(). Groups of buttons can be separated using addSeparator() or insertSeparator(). If a toolbar button is not appropriate, a widget can be inserted instead using addWidget() or insertWidget(). Examples of suitable widgets are QSpinBox, QDoubleSpinBox, and QComboBox. When a toolbar button is pressed, it emits the actionTriggered() signal.
A toolbar can be fixed in place in a particular area (e.g., at the top of the window), or it can be movable between toolbar areas; see setMovable(), isMovable(), allowedAreas() and isAreaAllowed().
When a toolbar is resized in such a way that it is too small to show all the items it contains, an extension button will appear as the last item in the toolbar. Pressing the extension button will pop up a menu containing the items that does not currently fit in the toolbar.
When a QToolBar is not a child of a QMainWindow, it loses the ability to populate the extension pop up with widgets added to the toolbar using addWidget(). Please use widget actions created by inheriting QWidgetAction and implementing QWidgetAction::createWidget() instead.
See also QToolButton, QMenu, QAction, and Application Example.
Property Documentation
allowedAreas : Qt::ToolBarAreas
This property holds areas where the toolbar may be placed.
The default is Qt::AllToolBarAreas.
This property only makes sense if the toolbar is in a QMainWindow.
Access functions:
Qt::ToolBarAreas | allowedAreas() const |
void | setAllowedAreas(Qt::ToolBarAreas areas) |
Notifier signal:
void | allowedAreasChanged(Qt::ToolBarAreas allowedAreas) |
See also movable.
floatable : bool
This property holds whether the toolbar can be dragged and dropped as an independent window.
The default is true.
Access functions:
bool | isFloatable() const |
void | setFloatable(bool floatable) |
floating : const bool
This property holds whether the toolbar is an independent window.
By default, this property is true
.
Access functions:
bool | isFloating() const |
See also QWidget::isWindow().
iconSize : QSize
This property holds size of icons in the toolbar.
The default size is determined by the application's style and is derived from the QStyle::PM_ToolBarIconSize pixel metric. It is the maximum size an icon can have. Icons of smaller size will not be scaled up.
Access functions:
QSize | iconSize() const |
void | setIconSize(const QSize & iconSize) |
Notifier signal:
void | iconSizeChanged(const QSize & iconSize) |
movable : bool
This property holds whether the user can move the toolbar within the toolbar area, or between toolbar areas.
By default, this property is true
.
This property only makes sense if the toolbar is in a QMainWindow.
Access functions:
bool | isMovable() const |
void | setMovable(bool movable) |
Notifier signal:
void | movableChanged(bool movable) |
See also allowedAreas.
orientation : Qt::Orientation
This property holds orientation of the toolbar.
The default is Qt::Horizontal.
This function should not be used when the toolbar is managed by QMainWindow. You can use QMainWindow::addToolBar() or QMainWindow::insertToolBar() if you wish to move a toolbar that is already added to a main window to another Qt::ToolBarArea.
Access functions:
Qt::Orientation | orientation() const |
void | setOrientation(Qt::Orientation orientation) |
Notifier signal:
void | orientationChanged(Qt::Orientation orientation) |
toolButtonStyle : Qt::ToolButtonStyle
This property holds the style of toolbar buttons.
This property defines the style of all tool buttons that are added as QActions. Note that if you add a QToolButton with the addWidget() method, it will not get this button style.
To have the style of toolbuttons follow the system settings, set this property to Qt::ToolButtonFollowStyle. On Unix, the user settings from the desktop environment will be used. On other platforms, Qt::ToolButtonFollowStyle means icon only.
The default is Qt::ToolButtonIconOnly.
Access functions:
Qt::ToolButtonStyle | toolButtonStyle() const |
void | setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle) |
Notifier signal:
void | toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle) |
Member Function Documentation
QToolBar::QToolBar(const QString & title, QWidget * parent = 0)
Constructs a QToolBar with the given parent.
The given window title identifies the toolbar and is shown in the context menu provided by QMainWindow.
See also setWindowTitle().
QToolBar::QToolBar(QWidget * parent = 0)
Constructs a QToolBar with the given parent.
QToolBar::~QToolBar()
Destroys the toolbar.
QAction * QToolBar::actionAt(const QPoint & p) const
Returns the action at point p. This function returns zero if no action was found.
See also QWidget::childAt().
QAction * QToolBar::actionAt(int x, int y) const
This is an overloaded function.
Returns the action at the point x, y. This function returns zero if no action was found.
[virtual protected]
void QToolBar::actionEvent(QActionEvent * event)
Reimplemented from QWidget::actionEvent().
[signal]
void QToolBar::actionTriggered(QAction * action)
This signal is emitted when an action in this toolbar is triggered. This happens when the action's tool button is pressed, or when the action is triggered in some other way outside the toolbar. The parameter holds the triggered action.
void QToolBar::addAction(QAction * action)
This is an overloaded function.
Appends the action to the toolbar's list of actions.
See also QMenu::addAction() and QWidget::addAction().
QAction * QToolBar::addAction(const QString & text)
This is an overloaded function.
Creates a new action with the given text. This action is added to the end of the toolbar.
QAction * QToolBar::addAction(const QIcon & icon, const QString & text)
This is an overloaded function.
Creates a new action with the given icon and text. This action is added to the end of the toolbar.
QAction * QToolBar::addAction(const QString & text, const QObject * receiver, const char * member)
This is an overloaded function.
Creates a new action with the given text. This action is added to the end of the toolbar. The action's triggered() signal is connected to member in receiver.
QAction * QToolBar::addAction(const QIcon & icon, const QString & text, const QObject * receiver, const char * member)
This is an overloaded function.
Creates a new action with the given icon and text. This action is added to the end of the toolbar. The action's triggered() signal is connected to member in receiver.
QAction * QToolBar::addSeparator()
Adds a separator to the end of the toolbar.
See also insertSeparator().
QAction * QToolBar::addWidget(QWidget * widget)
Adds the given widget to the toolbar as the toolbar's last item.
The toolbar takes ownership of widget.
If you add a QToolButton with this method, the toolbar's Qt::ToolButtonStyle will not be respected.
Note: You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.
See also insertWidget().
[virtual protected]
void QToolBar::changeEvent(QEvent * event)
Reimplemented from QWidget::changeEvent().
void QToolBar::clear()
Removes all actions from the toolbar.
See also removeAction().
[virtual protected]
bool QToolBar::event(QEvent * event)
Reimplemented from QObject::event().
QAction * QToolBar::insertSeparator(QAction * before)
Inserts a separator into the toolbar in front of the toolbar item associated with the before action.
See also addSeparator().
QAction * QToolBar::insertWidget(QAction * before, QWidget * widget)
Inserts the given widget in front of the toolbar item associated with the before action.
Note: You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.
See also addWidget().
bool QToolBar::isAreaAllowed(Qt::ToolBarArea area) const
Returns true
if this toolbar is dockable in the given area; otherwise returns false
.
[virtual protected]
void QToolBar::paintEvent(QPaintEvent * event)
Reimplemented from QWidget::paintEvent().
QAction * QToolBar::toggleViewAction() const
Returns a checkable action that can be used to show or hide this toolbar.
The action's text is set to the toolbar's window title.
See also QAction::text and QWidget::windowTitle.
[signal]
void QToolBar::topLevelChanged(bool topLevel)
This signal is emitted when the floating property changes. The topLevel parameter is true if the toolbar is now floating; otherwise it is false.
This function was introduced in Qt 4.6.
See also isWindow().
[signal]
void QToolBar::visibilityChanged(bool visible)
This signal is emitted when the toolbar becomes visible (or invisible). This happens when the widget is hidden or shown.
This function was introduced in Qt 4.7.
QWidget * QToolBar::widgetForAction(QAction * action) const
Returns the widget associated with the specified action.
This function was introduced in Qt 4.2.
See also addWidget().
© 2015 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.