QToolBar Class

QToolBar 提供一个包含多个控件的可移动界面. 更多...

头文件: #include <QToolBar>
qmake: QT += widgets
基类: QWidget

属性

公有函数

QToolBar(const QString &title, QWidget *parent = Q_NULLPTR)
QToolBar(QWidget *parent = Q_NULLPTR)
~QToolBar()
QAction *actionAt(const QPoint &p) const
QAction *actionAt(int x, int y) const
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 *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method)
QAction *addAction(const QString &text, Functor functor)
QAction *addAction(const QString &text, const QObject *context, Functor functor)
QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method)
QAction *addAction(const QIcon &icon, const QString &text, Functor functor)
QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor)
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

公有槽函数

void setIconSize(const QSize &iconSize)
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject

信号

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)

重新实现的受保护函数

virtual void actionEvent(QActionEvent *event)
virtual void changeEvent(QEvent *event)
virtual bool event(QEvent *event)
virtual void paintEvent(QPaintEvent *event)
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

QToolBar 提供一个包含多个控件的可移动界面.

工具条调用 addAction() 或 insertAction() 添加 actions 和 对应的 按钮 . 调用 addSeparator() or insertSeparator() 将按钮分组. 如果工具栏的按钮不符合要求, 你可以调用 addWidget() 或 insertWidget() 添加widget. 如, QSpinBox, QDoubleSpinBox, QComboBox. 按下工具栏按钮时, QToolBar会发出 actionTriggered() 信号.

工具栏可以固定在特定区域 (如., 窗口顶部), 也可以在不同区域移动; 参见 setMovable(), isMovable(), allowedAreas() 和 isAreaAllowed().

调整工具栏的大小, 使工具栏无法包含所有内容时, 工具栏上会显示一个扩展按钮. 按下扩展按钮将弹出一个菜单, 显示当前无法显示的内容.

QToolBar 不是 QMainWindow 的子对象时, 使用 addWidget() 加到工具栏上的widgets无法弹出. 你需要子类化 QWidgetAction, 并实现 QWidgetAction::createWidget() 函数.

参见 QToolButton, QMenu, QAction, Application Example.

属性

allowedAreas : Qt::ToolBarAreas

areas where the toolbar may be placed

The default is Qt::AllToolBarAreas.

This property only makes sense if the toolbar is in a QMainWindow.

访问函数:

Qt::ToolBarAreas allowedAreas() const
void setAllowedAreas(Qt::ToolBarAreas areas)

Notifier signal:

void allowedAreasChanged(Qt::ToolBarAreas allowedAreas)

参见 movable.

floatable : bool

This property holds whether the toolbar can be dragged and dropped as an independent window.

The default is true.

访问函数:

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.

访问函数:

bool isFloating() const

参见 QWidget::isWindow().

iconSize : QSize

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.

访问函数:

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.

访问函数:

bool isMovable() const
void setMovable(bool movable)

Notifier signal:

void movableChanged(bool movable)

参见 allowedAreas.

orientation : Qt::Orientation

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.

访问函数:

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.

访问函数:

Qt::ToolButtonStyle toolButtonStyle() const
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)

Notifier signal:

void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)

成员函数

QToolBar::QToolBar(const QString &title, QWidget *parent = Q_NULLPTR)

Constructs a QToolBar with the given parent.

The given window title identifies the toolbar and is shown in the context menu provided by QMainWindow.

参见 setWindowTitle().

QToolBar::QToolBar(QWidget *parent = Q_NULLPTR)

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.

参见 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)

重新实现 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.

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::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method)

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 the method of the receiver.

This function was introduced in Qt 5.6.

QAction *QToolBar::addAction(const QString &text, Functor functor)

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 the functor.

This function was introduced in Qt 5.6.

QAction *QToolBar::addAction(const QString &text, const QObject *context, Functor functor)

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 the functor.

If context is destroyed, the functor will not be called.

This function was introduced in Qt 5.6.

QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method)

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 the method of the receiver.

This function was introduced in Qt 5.6.

QAction *QToolBar::addAction(const QIcon &icon, const QString &text, Functor functor)

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 the functor.

This function was introduced in Qt 5.6.

QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor)

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 the functor.

If context is destroyed, the functor will not be called.

This function was introduced in Qt 5.6.

QAction *QToolBar::addSeparator()

Adds a separator to the end of the toolbar.

参见 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.

参见 insertWidget().

[signal] void QToolBar::allowedAreasChanged(Qt::ToolBarAreas allowedAreas)

This signal is emitted when the collection of allowed areas for the toolbar is changed. The new areas in which the toolbar can be positioned are specified by allowedAreas.

Note: Notifier signal for property allowedAreas.

参见 allowedAreas.

[virtual protected] void QToolBar::changeEvent(QEvent *event)

重新实现 QWidget::changeEvent().

void QToolBar::clear()

Removes all actions from the toolbar.

参见 removeAction().

[virtual protected] bool QToolBar::event(QEvent *event)

重新实现 QObject::event().

[signal] void QToolBar::iconSizeChanged(const QSize &iconSize)

This signal is emitted when the icon size is changed. The iconSize parameter holds the toolbar's new icon size.

Note: Notifier signal for property iconSize.

参见 iconSize and QMainWindow::iconSize.

QAction *QToolBar::insertSeparator(QAction *before)

Inserts a separator into the toolbar in front of the toolbar item associated with the before action.

参见 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.

参见 addWidget().

bool QToolBar::isAreaAllowed(Qt::ToolBarArea area) const

Returns true if this toolbar is dockable in the given area; otherwise returns false.

[signal] void QToolBar::movableChanged(bool movable)

This signal is emitted when the toolbar becomes movable or fixed. If the toolbar can be moved, movable is true; otherwise it is false.

Note: Notifier signal for property movable.

参见 movable.

[signal] void QToolBar::orientationChanged(Qt::Orientation orientation)

This signal is emitted when the orientation of the toolbar changes. The orientation parameter holds the toolbar's new orientation.

Note: Notifier signal for property orientation.

参见 orientation.

[virtual protected] void QToolBar::paintEvent(QPaintEvent *event)

重新实现 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.

参见 QAction::text and QWidget::windowTitle.

[signal] void QToolBar::toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)

This signal is emitted when the tool button style is changed. The toolButtonStyle parameter holds the toolbar's new tool button style.

Note: Notifier signal for property toolButtonStyle.

参见 toolButtonStyle and QMainWindow::toolButtonStyle.

[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.

参见 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.

参见 addWidget().