QToolBar 类

The QToolBar class provides a movable panel that contains a set of controls. 更多...

头: #include <QToolBar>
继承: QWidget
继承者:

特性

公共函数

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

公共槽

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 )
virtual void changeEvent (QEvent * event )
virtual void childEvent (QChildEvent * event )
virtual bool event (QEvent * event )
virtual void paintEvent (QPaintEvent * event )
virtual void resizeEvent (QResizeEvent * event )

额外继承成员

详细描述

The QToolBar class provides a movable panel that contains a set of controls.

工具栏按钮被添加通过添加 actions ,使用 addAction () 或 insertAction ()。按钮组的分隔可以使用 addSeparator () 或 insertSeparator ()。若工具栏按钮不合适,可以插入 Widget 而不是使用 addWidget () 或 insertWidget (); examples of suitable widgets are QSpinBox , QDoubleSpinBox ,和 QComboBox . When a toolbar button is pressed it emits the actionTriggered () 信号。

A toolbar can be fixed in place in a particular area (e.g. at the top of the window), or it can be movable ( isMovable ()) between toolbar areas; see allowedAreas () 和 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.

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 () 代替。

另请参阅 QToolButton , QMenu , QAction ,和 应用程序范例 .

特性文档编制

allowedAreas : Qt::ToolBarAreas

This property holds areas where the toolbar may be placed.

默认为 Qt::AllToolBarAreas .

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

访问函数:

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

通知程序信号:

void allowedAreasChanged (Qt::ToolBarAreas allowedAreas )

另请参阅 movable .

floatable : bool

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

默认为 true。

访问函数:

bool isFloatable () const
void setFloatable (bool floatable )

floating : const bool

This property holds whether the toolbar is an independent window.

默认情况下,此特性为 true。

访问函数:

bool isFloating () const

另请参阅 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.

访问函数:

QSize iconSize () const
void setIconSize (const QSize & iconSize )

通知程序信号:

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.

默认情况下,此特性为 true。

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

访问函数:

bool isMovable () const
void setMovable (bool movable )

通知程序信号:

void movableChanged (bool movable )

另请参阅 allowedAreas .

orientation : Qt::Orientation

This property holds orientation of the toolbar.

默认为 Qt::Horizontal .

This function should not be used when the toolbar is managed by QMainWindow 。可以使用 QMainWindow::addToolBar () 或 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 )

通知程序信号:

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 QAction s. Note that if you add a QToolButton 采用 addWidget () method, it will not get this button style.

默认为 Qt::ToolButtonIconOnly .

访问函数:

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

通知程序信号:

void toolButtonStyleChanged (Qt::ToolButtonStyle toolButtonStyle )

成员函数文档编制

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

构造 QToolBar 采用给定 parent .

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

另请参阅 setWindowTitle ().

QToolBar:: QToolBar ( QWidget * parent = 0)

构造 QToolBar 采用给定 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

这是重载函数。

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 tool bar. The parameter holds the triggered action .

void QToolBar:: addAction ( QAction * action )

这是重载函数。

追加动作 action to the toolbar's list of actions.

另请参阅 QMenu::addAction () 和 QWidget::addAction ().

QAction * QToolBar:: addAction (const QString & text )

这是重载函数。

创建新的动作采用给定 text 。此动作将被添加到工具栏末尾。

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

这是重载函数。

创建新的动作采用给定 icon and text 。此动作将被添加到工具栏末尾。

QAction * QToolBar:: addAction (const QString & text , const QObject * receiver , const char * member )

这是重载函数。

创建新的动作采用给定 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 )

这是重载函数。

Creates a new action with the icon icon 和文本 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.

另请参阅 insertSeparator ().

QAction * QToolBar:: addWidget ( QWidget * widget )

添加给定 widget to the toolbar as the toolbar's last item.

The toolbar takes ownership of widget .

若添加 QToolButton with this method, the tools bar's Qt::ToolButtonStyle will not be respected.

注意: 应使用 QAction::setVisible () to change the visibility of the widget. Using QWidget::setVisible (), QWidget::show () 和 QWidget::hide () does not work.

另请参阅 insertWidget ().

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

重实现自 QWidget::changeEvent ().

[virtual protected] void QToolBar:: childEvent ( QChildEvent * event )

重实现自 QObject::childEvent ().

void QToolBar:: clear ()

从工具栏移除所有动作。

另请参阅 removeAction ().

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

重实现自 QObject::event ().

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 )

插入给定 widget in front of the toolbar item associated with the before action.

注意:应使用 QAction::setVisible () to change the visibility of the widget. Using QWidget::setVisible (), QWidget::show () 和 QWidget::hide () does not work.

另请参阅 addWidget ().

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

Returns true if this toolbar is dockable in the given area ;否则返回 false。

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

重实现自 QWidget::paintEvent ().

[virtual protected] void QToolBar:: resizeEvent ( QResizeEvent * event )

重实现自 QWidget::resizeEvent ().

QAction * QToolBar:: toggleViewAction () const

Returns a checkable action that can be used to show or hide this toolbar.

动作的文本被设为工具栏的窗口标题。

另请参阅 QAction::text and QWidget::windowTitle .

[signal] void QToolBar:: topLevelChanged ( bool topLevel )

此信号发射当 floating 特性改变。 topLevel parameter is true if the toolbar is now floating; otherwise it is false.

该函数在 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.

该函数在 Qt 4.7 引入。

QWidget * QToolBar:: widgetForAction ( QAction * action ) const

返回的 Widget 关联指定 action .

该函数在 Qt 4.2 引入。

另请参阅 addWidget ().