QToolBar Class
QToolBar 类提供了一个包含一组控件的可移动面板。
Header | #include < QToolBar > |
---|---|
qmake | QT += widgets |
Inherits | QWidget |
Inherited By |
详细说明
工具栏按钮是通过使用addAction() 或insertAction() 添加操作来添加的。
可以使用addSeparator() 或insertSeparator() 分隔按钮组。
如果工具栏按钮不合适,可以使用addWidget() 或insertWidget() 插入小部件。合适的小部件的示例有QSpinBox、QDoubleSpinBox和QComboBox。
当按下工具栏按钮时,它会发出actionTriggered() 信号。
工具栏可以固定在特定区域(例如,在窗口顶部),也可以在工具栏区域之间移动;请参见setMovable() 、isMovable() 、allowedAreas() 和isreaallowed() 。
当工具栏的大小调整到太小而无法显示其包含的所有项目时,扩展按钮将作为工具栏中的最后一个项目出现。按扩展按钮将弹出一个菜单,其中包含当前不适合工具栏的项目。
当QToolBar不是QMainWindow的子级时,它将失去使用addWidget() 将小部件添加到工具栏的功能。请使用通过继承QWidgetAction 并实现 QWidgetAction::createWidget() 创建的小部件操作。
属性
-
allowedAreas: Qt::ToolBarAreas 可放置工具栏的区域
默认值为Qt::AllToolBarAreas。
仅当工具栏位于QMainWindow中时,此属性才有意义。- Qt::ToolBarAreas allowedAreas() const
- void setAllowedAreas(Qt::ToolBarAreas areas)
Notifier signal:
- void allowedAreasChanged(Qt::ToolBarAreas allowedAreas)
enum Qt::ToolBarArea
flags Qt::ToolBarAreasConstant Value Qt::NoToolBarArea 0 Qt::LeftToolBarArea 0x1 Qt::RightToolBarArea 0x2 Qt::TopToolBarArea 0x4 Qt::BottomToolBarArea 0x8 Qt::AllToolBarAreas ToolBarArea_Mask -
floatable: bool 工具栏是否可以作为独立窗口拖放
默认值为true。- bool isFloatable() const
- void setFloatable(bool floatable)
-
floating: const bool 工具栏是否为独立窗口
默认情况下,此属性为true。- bool isFloating() const
-
iconSize: QSize 工具栏中图标的大小
默认大小由应用程序的样式决定,并派生自QStyle::PM_ToolBarIconSize像素度量。
它是图标可以具有的最大大小。较小尺寸的图标将不会放大。- QSize iconSize() const
- void setIconSize(const QSize &iconSize)
Notifier signal:
- void iconSizeChanged(const QSize &iconSize)
-
movable: bool 是否可以在工具栏区域之间移动工具栏
默认情况下,此属性为true。
仅当工具栏位于QMainWindow中时,此属性才有意义。- bool isMovable() const
- void setMovable(bool movable)
Notifier signal:
- void movableChanged(bool movable)
-
orientation: Qt::Orientation 工具栏的方向
默认值为Qt::Horizontal。
当工具栏由QMainWindow管理时,不应使用此函数。如果要将已添加到主窗口的工具栏移动到另一个Qt::ToolBarArea,可以使用QMainWindow::addToolBar() 或QMainWindow::insertToolBar() 。- Qt::Orientation orientation() const
- void setOrientation(Qt::Orientation orientation)
Notifier signal:
- void orientationChanged(Qt::Orientation orientation)
-
toolButtonStyle: Qt::ToolButtonStyle 工具栏按钮的样式
此属性定义作为QActions添加的所有工具按钮的样式。请注意,如果使用addWidget() 方法添加QToolButton,它将不会获得此按钮样式。
要使toolbuttons的样式遵循系统设置,请将此属性设置为Qt::ToolButtonFollowStyle。在Unix上,将使用桌面环境中的用户设置。在其他平台上,Qt::ToolButtonFollowStyle仅表示图标。默认值为Qt::ToolButtonIconOnly。
- Qt::ToolButtonStyle toolButtonStyle() const
- void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
公共函数
构造和析构
- QToolBar(QWidget *parent = nullptr)
- QToolBar(const QString &title, QWidget *parent = nullptr)
- virtual ~QToolBar()
属性相关
- Qt::ToolBarAreas allowedAreas() const
void setAllowedAreas(Qt::ToolBarAreas areas) - bool isFloatable() const
void setFloatable(bool floatable) - bool isFloating() const
- QSize iconSize() const
void setIconSize(const QSize &iconSize) - bool isMovable() const
void setMovable(bool movable) - Qt::Orientation orientation() const
void setOrientation(Qt::Orientation orientation) - Qt::ToolButtonStyle toolButtonStyle() const
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
增加清除
- 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, Functor functor)
- QAction * addAction(const QString &text, const QObject *context, Functor functor)
- 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)
- void clear()
- QAction * insertSeparator(QAction *before)
- QAction * insertWidget(QAction *before, QWidget *widget)
其它
- bool isAreaAllowed(Qt::ToolBarArea area) const
- QAction * toggleViewAction() const 返回可用于显示或隐藏此工具栏的可检查操作
- QWidget * widgetForAction(QAction *action) const 返回与指定操作关联的小部件
公共槽
- void setIconSize(const QSize &iconSize)
- void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
信号
- 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) override
- virtual void changeEvent(QEvent *event) override
- virtual bool event(QEvent *event) override
- virtual void paintEvent(QPaintEvent *event) override