QToolButton class provides a quick-access button to commands or options, usually used inside a QToolBar . 更多...
头: | #include <QToolButton> |
qmake: | QT += widgets |
继承: | QAbstractButton |
enum | ToolButtonPopupMode { DelayedPopup, MenuButtonPopup, InstantPopup } |
QToolButton (QWidget * parent = Q_NULLPTR) | |
~QToolButton () | |
Qt::ArrowType | arrowType () const |
bool | autoRaise () const |
QAction * | defaultAction () const |
QMenu * | menu () const |
ToolButtonPopupMode | popupMode () const |
void | setArrowType (Qt::ArrowType type ) |
void | setAutoRaise (bool enable ) |
void | setMenu (QMenu * menu ) |
void | setPopupMode (ToolButtonPopupMode mode ) |
Qt::ToolButtonStyle | toolButtonStyle () const |
virtual QSize | minimumSizeHint () const |
virtual QSize | sizeHint () const |
void | setDefaultAction (QAction * action ) |
void | setToolButtonStyle (Qt::ToolButtonStyle style ) |
void | showMenu () |
void | triggered (QAction * action ) |
void | initStyleOption (QStyleOptionToolButton * option ) const |
virtual void | actionEvent (QActionEvent * event ) |
virtual void | changeEvent (QEvent * e ) |
virtual void | enterEvent (QEvent * e ) |
virtual bool | event (QEvent * event ) |
virtual bool | hitButton (const QPoint & pos ) const |
virtual void | leaveEvent (QEvent * e ) |
virtual void | mousePressEvent (QMouseEvent * e ) |
virtual void | mouseReleaseEvent (QMouseEvent * e ) |
virtual void | nextCheckState () |
virtual void | paintEvent (QPaintEvent * event ) |
virtual void | timerEvent (QTimerEvent * e ) |
QToolButton class provides a quick-access button to commands or options, usually used inside a QToolBar .
工具按钮是能对特定命令 (或选项) 提供快速访问的特殊按钮。
通常,工具按钮的创建是在新的 QAction 实例被创建采用 QToolBar::addAction () 或现有动作被添加到工具栏采用 QToolBar::addAction ()。按如任何其它 Widget 的相同方式构造工具按钮,并将它们同其它小部件一起排列在布局中是可能的。
One classic use of a tool button is to select tools; for example, the "pen" tool in a drawing program. This would be implemented by using a QToolButton as a toggle button (see setCheckable ()).
QToolButton supports auto-raising. In auto-raise mode, the button draws a 3D frame only when the mouse points at it. The feature is automatically turned on when a button is used inside a QToolBar 。改变它采用 setAutoRaise ().
工具按钮的图标被设为 QIcon . This makes it possible to specify different pixmaps for the disabled and active state. The disabled pixmap is used when the button's functionality is not available. The active pixmap is displayed when the button is auto-raised because the mouse pointer is hovering over it.
按钮外观和尺度的调节采用 setToolButtonStyle () 和 setIconSize (). When used inside a QToolBar 在 QMainWindow , the button automatically adjusts to QMainWindow 's settings (see QMainWindow::setToolButtonStyle () 和 QMainWindow::setIconSize ()). Instead of an icon, a tool button can also display an arrow symbol, specified with arrowType .
A tool button can offer additional choices in a popup menu. The popup menu can be set using setMenu ()。使用 setPopupMode () to configure the different modes available for tool buttons with a menu set. The default mode is DelayedPopupMode which is sometimes used with the "Back" button in a web browser. After pressing and holding the button down for a while, a menu pops up showing a list of possible pages to jump to. The timeout is style dependent, see QStyle::SH_ToolButton_PopupDelay .
Qt Assistant's toolbar contains tool buttons that are associated with actions used in other parts of the main window. |
另请参阅 QPushButton , QToolBar , QMainWindow , QAction ,和 GUI 设计手册:按钮 .
描述拥有菜单集或包含动作列表的工具按钮应如何弹出菜单。
常量 | 值 | 描述 |
---|---|---|
QToolButton::DelayedPopup
|
0
|
After pressing and holding the tool button down for a certain amount of time (the timeout is style dependent, see QStyle::SH_ToolButton_PopupDelay ), the menu is displayed. A typical application example is the "back" button in some web browsers's tool bars. If the user clicks it, the browser simply browses back to the previous page. If the user presses and holds the button down for a while, the tool button shows a menu containing the current history list |
QToolButton::MenuButtonPopup
|
1
|
In this mode the tool button displays a special arrow to indicate that a menu is present. The menu is displayed when the arrow part of the button is pressed. |
QToolButton::InstantPopup
|
2
|
不延迟显示菜单,当按下工具按钮时。在此模式下,按钮自身的动作不会被触发。 |
This property holds whether the button displays an arrow instead of a normal icon
This displays an arrow as the icon for the QToolButton .
默认情况下,此特性被设为 Qt::NoArrow .
访问函数:
Qt::ArrowType | arrowType () const |
void | setArrowType (Qt::ArrowType type ) |
此特性保持是否启用自动上升。
默认被禁用 (即:false)。
此特性在 macOS 目前是忽略的,当使用 QMacStyle 时。
访问函数:
bool | autoRaise () const |
void | setAutoRaise (bool enable ) |
描述用于工具按钮的菜单的弹出方式
默认情况下,此特性被设为 DelayedPopup .
访问函数:
ToolButtonPopupMode | popupMode () const |
void | setPopupMode (ToolButtonPopupMode mode ) |
This property holds whether the tool button displays an icon only, text only, or text beside/below the icon.
默认为 Qt::ToolButtonIconOnly .
要让工具按钮样式遵循系统设置,将此特性设为 Qt::ToolButtonFollowStyle 。在 Unix,将使用来自桌面环境的用户设置。在其它平台, Qt::ToolButtonFollowStyle 意味着仅图标。
QToolButton automatically connects this slot to the relevant signal in the QMainWindow in which is resides.
访问函数:
Qt::ToolButtonStyle | toolButtonStyle () const |
void | setToolButtonStyle (Qt::ToolButtonStyle style ) |
构造空工具按钮采用父级 parent .
销毁对象并释放任何分配资源。
[virtual protected]
void
QToolButton::
actionEvent
(
QActionEvent
*
event
)
重实现自 QWidget::actionEvent ().
[virtual protected]
void
QToolButton::
changeEvent
(
QEvent
*
e
)
重实现自 QWidget::changeEvent ().
返回默认动作。
另请参阅 setDefaultAction ().
[virtual protected]
void
QToolButton::
enterEvent
(
QEvent
*
e
)
重实现自 QWidget::enterEvent ().
[virtual protected]
bool
QToolButton::
event
(
QEvent
*
event
)
重实现自 QObject::event ().
[virtual protected]
bool
QToolButton::
hitButton
(const
QPoint
&
pos
) const
重实现自 QAbstractButton::hitButton ().
[protected]
void
QToolButton::
initStyleOption
(
QStyleOptionToolButton
*
option
) const
初始化 option 采用值来自此 QToolButton 。此方法对子类是有用的,当需要 QStyleOptionToolButton ,但不希望自己填充所有信息。
另请参阅 QStyleOption::initFrom ().
[virtual protected]
void
QToolButton::
leaveEvent
(
QEvent
*
e
)
重实现自 QWidget::leaveEvent ().
Returns the associated menu, or 0 if no menu has been defined.
另请参阅 setMenu ().
[virtual]
QSize
QToolButton::
minimumSizeHint
() const
重实现自 QWidget::minimumSizeHint ().
[virtual protected]
void
QToolButton::
mousePressEvent
(
QMouseEvent
*
e
)
重实现自 QWidget::mousePressEvent ().
[virtual protected]
void
QToolButton::
mouseReleaseEvent
(
QMouseEvent
*
e
)
重实现自 QWidget::mouseReleaseEvent ().
[virtual protected]
void
QToolButton::
nextCheckState
()
重实现自 QAbstractButton::nextCheckState ().
[virtual protected]
void
QToolButton::
paintEvent
(
QPaintEvent
*
event
)
重实现自 QWidget::paintEvent ().
Paints the button in response to the paint event .
[slot]
void
QToolButton::
setDefaultAction
(
QAction
*
action
)
将默认动作设为 action .
If a tool button has a default action, the action defines the button's properties like text, icon, tool tip, etc.
另请参阅 defaultAction ().
Associates the given menu with this tool button.
The menu will be shown according to the button's popupMode .
Ownership of the menu is not transferred to the tool button.
另请参阅 menu ().
[slot]
void
QToolButton::
showMenu
()
展示 (弹出) 关联的弹出菜单。若没有这种菜单,此函数什么都不做。此函数直到用户关闭弹出菜单后才返回。
[virtual]
QSize
QToolButton::
sizeHint
() const
重实现自 QWidget::sizeHint ().
[virtual protected]
void
QToolButton::
timerEvent
(
QTimerEvent
*
e
)
重实现自 QObject::timerEvent ().
[signal]
void
QToolButton::
triggered
(
QAction
*
action
)
此信号被发射当给定 action 被触发。
The action may also be associated with other parts of the user interface, such as menu items and keyboard shortcuts. Sharing actions in this way helps make the user interface more consistent and is often less work to implement.