QToolBar 類

QToolBar 類提供包含一組控件的可移動麵闆。 更多...

頭: #include <QToolBar>
qmake: QT += widgets
繼承: QWidget

特性

公共函數

QToolBar (QWidget * parent = nullptr)
QToolBar (const QString & title , QWidget * parent = nullptr)
virtual ~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 , 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 )
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 ) override
virtual void changeEvent (QEvent * event ) override
virtual bool event (QEvent * event ) override
virtual void paintEvent (QPaintEvent * event ) override

詳細描述

工具欄按鈕被添加通過添加 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 between toolbar areas; see setMovable (), isMovable (), 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 do not currently fit in the toolbar.

When a 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

可以放置工具欄的區域

默認為 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

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

工具欄的取嚮

默認為 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::ToolButtonFollowStyle 。在 Unix,將使用來自桌麵環境的用戶設置。在其它平颱, Qt::ToolButtonFollowStyle 意味著僅圖標。

默認為 Qt::ToolButtonIconOnly .

訪問函數:

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

通知程序信號:

void toolButtonStyleChanged (Qt::ToolButtonStyle toolButtonStyle )

成員函數文檔編製

QToolBar:: QToolBar ( QWidget * parent = nullptr)

構造 QToolBar 采用給定 parent .

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

構造 QToolBar 采用給定 parent .

給定窗口 title identifies the toolbar and is shown in the context menu provided by QMainWindow .

另請參閱 setWindowTitle ().

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

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

注意: 通知程序信號對於特性 allowedAreas .

另請參閱 allowedAreas .

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

注意: 通知程序信號對於特性 iconSize .

另請參閱 iconSize and QMainWindow::iconSize .

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

This signal is emitted when the toolbar becomes movable or fixed. If the toolbar can be moved, movable 為 true;否則為 false。

注意: 通知程序信號對於特性 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.

注意: 通知程序信號對於特性 orientation .

另請參閱 orientation .

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

此信號發射,當工具按鈕樣式改變時。 toolButtonStyle 參數保持工具欄的新工具按鈕樣式。

注意: 通知程序信號對於特性 toolButtonStyle .

另請參閱 toolButtonStyle and QMainWindow::toolButtonStyle .

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

此信號發射,當工具欄變為 visible (或不可見)。這發生,當隱藏 (或展示) Widget 時。

該函數在 Qt 4.7 引入。

[虛擬] QToolBar:: ~QToolBar ()

銷毀工具欄。

QAction *QToolBar:: actionAt (const QPoint & p ) const

返迴的動作在點 p 。此函數返迴 0,若未找到操作。

另請參閱 QWidget::childAt ().

QAction *QToolBar:: actionAt ( int x , int y ) const

這是重載函數。

返迴的動作在點 x , y 。此函數返迴 0,若未找到操作。

[override virtual protected] void QToolBar:: actionEvent ( QActionEvent * event )

重實現: QWidget::actionEvent (QActionEvent *event).

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 )

這是重載函數。

創建新動作采用給定 icon and text . This action is added to the end of the toolbar. The action's triggered() signal is connected to member in receiver .

template <typename Functor> QAction *QToolBar:: addAction (const QString & text , Functor functor )

這是重載函數。

創建新動作采用給定 text . This action is added to the end of the toolbar. The action's triggered() 信號被連接到 functor .

該函數在 Qt 5.6 引入。

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

這是重載函數。

創建新動作采用給定 text . This action is added to the end of the toolbar. The action's triggered() 信號被連接到 functor functor can be a pointer to a member function in the context 對象。

context object is destroyed, the functor 不會被調用。

該函數在 Qt 5.6 引入。

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

這是重載函數。

創建新動作采用給定 icon and text . This action is added to the end of the toolbar. The action's triggered() 信號被連接到 functor .

該函數在 Qt 5.6 引入。

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

這是重載函數。

創建新動作采用給定 icon and text . This action is added to the end of the toolbar. The action's triggered() 信號被連接到 functor functor can be a pointer to a member function of the context 對象。

context object is destroyed, the functor 不會被調用。

該函數在 Qt 5.6 引入。

QAction *QToolBar:: addSeparator ()

把分隔符添加到工具欄末尾。

另請參閱 insertSeparator ().

QAction *QToolBar:: addWidget ( QWidget * widget )

添加給定 widget 到工具欄作為工具欄的最後項。

工具欄擁有所有權對於 widget .

若添加 QToolButton 采用此方法,工具欄的 Qt::ToolButtonStyle will not be respected.

注意: 應使用 QAction::setVisible () 以改變 Widget 的可見性。使用 QWidget::setVisible (), QWidget::show () 和 QWidget::hide () 不工作。

另請參閱 insertWidget ().

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

重實現: QWidget::changeEvent (QEvent *event).

void QToolBar:: clear ()

從工具欄移除所有動作。

另請參閱 removeAction ().

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

重實現: QWidget::event (QEvent *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 () 以改變 Widget 的可見性。使用 QWidget::setVisible (), QWidget::show () 和 QWidget::hide () 不工作。

另請參閱 addWidget ().

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

返迴 true 若此工具欄可停放在給定 area ;否則返迴 false .

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

重實現: QWidget::paintEvent (QPaintEvent *event).

QAction *QToolBar:: toggleViewAction () const

返迴可以用於展示 (或隱藏) 此工具欄的可復選動作。

動作的文本被設為工具欄的窗口標題。

另請參閱 QAction::text and QWidget::windowTitle .

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

返迴的 Widget 關聯指定 action .

該函數在 Qt 4.2 引入。

另請參閱 addWidget ().