PySide6.QtWidgets.QToolBar

class QToolBar

QToolBar 类提供了一个可移动的面板,其中包含一组控件。更多

PySide6.QtWidgets.QToolBar 的继承图

概要

属性

方法

虚拟方法

插槽

信号

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

工具栏通常通过调用addToolBar(const QString &title)来创建,但也可以作为第一个小部件添加到QVBoxLayout中,例如。

工具栏按钮通过添加动作来添加,使用addAction()insertAction()。按钮组可以使用addSeparator()insertSeparator()进行分隔。如果工具栏按钮不合适,可以使用addWidget()insertWidget()插入一个小部件。适合的小部件示例包括QSpinBoxQDoubleSpinBoxQComboBox。当按下工具栏按钮时,它会发出actionTriggered()信号。

工具栏可以固定在特定区域(例如,窗口的顶部),也可以在工具栏区域之间移动;请参阅 setMovable()isMovable()allowedAreas()isAreaAllowed()

当工具栏调整大小以至于太小无法显示所有包含的项目时,扩展按钮将作为工具栏中的最后一个项目出现。按下扩展按钮将弹出一个菜单,其中包含当前无法放入工具栏的项目。

QToolBar不是QMainWindow的子元素时,它将失去使用addWidget()添加到工具栏的小部件填充扩展弹出窗口的能力。请使用通过继承QWidgetAction并实现createWidget()创建的小部件操作。

另请参阅

QToolButton QMenu QAction

注意

当使用from __feature__ import true_property时,属性可以直接使用,否则通过访问器函数使用。

property allowedAreasᅟ: Combination of Qt.ToolBarArea

此属性包含工具栏可以放置的区域。

默认是 Qt::AllToolBarAreas。

此属性仅在工具栏位于QMainWindow中时才有意义。

另请参阅

movable

Access functions:
property floatableᅟ: bool

此属性表示工具栏是否可以作为一个独立的窗口进行拖放。

默认值为 true。

Access functions:
property floatingᅟ: bool

此属性表示工具栏是否是一个独立的窗口。

默认情况下,此属性为 true

另请参阅

isWindow()

Access functions:
property iconSizeᅟ: QSize

此属性保存工具栏中图标的大小。

默认大小由应用程序的样式决定,并源自PM_ToolBarIconSize像素度量。它是图标可以拥有的最大尺寸。较小尺寸的图标将不会被放大。

Access functions:
property movableᅟ: bool

此属性决定用户是否可以在工具栏区域内或工具栏区域之间移动工具栏。

默认情况下,此属性为 true

此属性仅在工具栏位于QMainWindow中时才有意义。

另请参阅

allowedAreas

Access functions:
property orientationᅟ: Qt.Orientation

此属性保存工具栏的方向。

默认是 Qt::Horizontal。

当工具栏由QMainWindow管理时,不应使用此函数。如果您希望将已添加到主窗口的工具栏移动到另一个Qt::ToolBarArea,可以使用addToolBar()insertToolBar()

Access functions:
property toolButtonStyleᅟ: Qt.ToolButtonStyle

此属性保存工具栏按钮的样式。

此属性定义了作为QActions添加的所有工具按钮的样式。请注意,如果您使用addWidget()方法添加QToolButton,它将不会获得此按钮样式。

要使工具按钮的样式遵循系统设置,请将此属性设置为Qt::ToolButtonFollowStyle。在Unix上,将使用桌面环境的用户设置。在其他平台上,Qt::ToolButtonFollowStyle表示仅显示图标。

默认是Qt::ToolButtonIconOnly。

Access functions:
__init__([parent=None])
Parameters:

父级QWidget

使用给定的parent构造一个QToolBar

__init__(title[, parent=None])
Parameters:
  • 标题 – str

  • parentQWidget

使用给定的parent构造一个QToolBar

给定的窗口title标识工具栏,并在QMainWindow提供的上下文菜单中显示。

另请参阅

setWindowTitle()

actionAt(p)
Parameters:

pQPoint

Return type:

QAction

返回点 p 处的动作。如果未找到动作,此函数返回零。

另请参阅

childAt()

actionAt(x, y)
Parameters:
  • x – 整数

  • y – 整数

Return type:

QAction

这是一个重载函数。

返回在点 x, y 处的动作。如果未找到动作,此函数返回零。

actionGeometry(action)
Parameters:

动作QAction

Return type:

QRect

actionTriggered(action)
Parameters:

动作QAction

当工具栏中的某个操作被触发时,会发出此信号。这发生在操作的工具按钮被按下时,或者当操作在工具栏外以其他方式被触发时。参数保存了被触发的 action

addSeparator()
Return type:

QAction

向工具栏的末尾添加一个分隔符。

另请参阅

insertSeparator()

addWidget(widget)
Parameters:

widgetQWidget

Return type:

QAction

将给定的widget添加到工具栏作为工具栏的最后一个项目。

工具栏接管了widget的所有权。

如果你用这个方法添加一个QToolButton,工具栏的Qt::ToolButtonStyle将不会被遵循。

注意

你应该使用QAction::setVisible()来改变小部件的可见性。使用setVisible()show()hide()不起作用。

另请参阅

insertWidget()

allowedAreas()
Return type:

ToolBarArea 的组合

另请参阅

setAllowedAreas()

属性 allowedAreasᅟ 的获取器。

allowedAreasChanged(allowedAreas)
Parameters:

allowedAreasToolBarArea 的组合

当工具栏允许的区域集合发生变化时,会发出此信号。工具栏可以放置的新区域由allowedAreas指定。

另请参阅

allowedAreas

属性 allowedAreasᅟ 的通知信号。

clear()

从工具栏中移除所有操作。

另请参阅

removeAction()

iconSize()
Return type:

QSize

另请参阅

setIconSize()

属性 iconSizeᅟ 的获取器。

iconSizeChanged(iconSize)
Parameters:

iconSizeQSize

当图标大小改变时,会发出此信号。iconSize 参数保存工具栏的新图标大小。

另请参阅

iconSize iconSize

属性 iconSizeᅟ 的通知信号。

initStyleOption(option)
Parameters:

选项QStyleOptionToolBar

insertSeparator(before)
Parameters:

之前QAction

Return type:

QAction

在与before操作关联的工具栏项前面插入一个分隔符。

另请参阅

addSeparator()

insertWidget(before, widget)
Parameters:
Return type:

QAction

在工具栏项前面插入给定的widget,该工具栏项与before操作相关联。

注意:你应该使用 QAction::setVisible() 来改变小部件的可见性。使用 setVisible()show()hide() 不起作用。

另请参阅

addWidget()

isAreaAllowed(area)
Parameters:

区域ToolBarArea

Return type:

布尔

如果此工具栏可以在给定的area中停靠,则返回true;否则返回false

isFloatable()
Return type:

布尔

属性 floatableᅟ 的获取器。

isFloating()
Return type:

布尔

属性 floatingᅟ 的获取器。

isMovable()
Return type:

布尔

属性 movableᅟ 的获取器。

movableChanged(movable)
Parameters:

movable – 布尔值

当工具栏变为可移动或固定时,会发出此信号。如果工具栏可以移动,movable 为 true;否则为 false。

另请参阅

movable

属性 movableᅟ 的通知信号。

orientation()
Return type:

方向

另请参阅

setOrientation()

属性 orientationᅟ 的获取器。

orientationChanged(orientation)
Parameters:

方向Orientation

当工具栏的方向发生变化时,会发出此信号。orientation 参数保存工具栏的新方向。

另请参阅

orientation

属性 orientationᅟ 的通知信号。

setAllowedAreas(areas)
Parameters:

areasToolBarArea 的组合

另请参阅

allowedAreas()

属性 allowedAreasᅟ 的设置器。

setFloatable(floatable)
Parameters:

floatable – 布尔值

另请参阅

isFloatable()

属性 floatableᅟ 的设置器。

setIconSize(iconSize)
Parameters:

iconSizeQSize

另请参阅

iconSize()

属性 iconSizeᅟ 的设置器。

setMovable(movable)
Parameters:

movable – 布尔值

另请参阅

isMovable()

属性 movableᅟ 的设置器。

setOrientation(orientation)
Parameters:

方向Orientation

另请参阅

orientation()

属性 orientationᅟ 的设置器。

setToolButtonStyle(toolButtonStyle)
Parameters:

toolButtonStyleToolButtonStyle

另请参阅

toolButtonStyle()

属性 toolButtonStyleᅟ 的设置器。

toggleViewAction()
Return type:

QAction

返回一个可检查的操作,可用于显示或隐藏此工具栏。

操作的文本设置为工具栏的窗口标题。

另请参阅

windowTitle

toolButtonStyle()
Return type:

ToolButtonStyle

另请参阅

setToolButtonStyle()

属性 toolButtonStyleᅟ 的获取器。

toolButtonStyleChanged(toolButtonStyle)
Parameters:

toolButtonStyleToolButtonStyle

当工具按钮样式更改时,会发出此信号。toolButtonStyle 参数保存工具栏的新工具按钮样式。

属性 toolButtonStyleᅟ 的通知信号。

topLevelChanged(topLevel)
Parameters:

topLevel – 布尔值

floating属性发生变化时,会发出此信号。如果工具栏现在处于浮动状态,则topLevel参数为true;否则为false。

另请参阅

isWindow()

visibilityChanged(visible)
Parameters:

visible – 布尔值

当工具栏变为可见(或不可见)时,会发出此信号。当小部件被隐藏或显示时,会发生这种情况。

widgetForAction(action)
Parameters:

动作QAction

Return type:

QWidget

返回与指定的action相关联的小部件。

另请参阅

addWidget()