IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QToolBar Class

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

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QToolBar Class

  • Header: QToolBar

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Widgets)

    target_link_libraries(mytarget PRIVATE Qt6::Widgets)

  • qmake: QT += widgets

  • Inherits: QWidget

  • Group: QToolBar is part of mainwindow-classes

Detailed Description

Toolbar buttons are added by adding actions, using addAction() or insertAction(). Groups of buttons can be separated using addSeparator() or insertSeparator(). If a toolbar button is not appropriate, a widget can be inserted instead using addWidget() or insertWidget(). Examples of suitable widgets are QSpinBox, QDoubleSpinBox, and QComboBox. When a toolbar button is pressed, it emits the actionTriggered() signal.

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() and 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() instead.

See Also

Property Documentation

 

allowedAreas : Qt::ToolBarAreas

areas where the toolbar may be placed

The default is Qt::AllToolBarAreas.

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

Access functions:

  • allowedAreas() const

  • void setAllowedAreas( areas)

Notifier signal:

See Also

See also movable

floatable : bool

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

The default is true.

Access functions:

  • bool isFloatable() const

  • void setFloatable(bool floatable)

[read-only] floating : const bool

This property holds whether the toolbar is an independent window.

By default, this property is true.

Access functions:

  • bool isFloating() const

See Also

See also 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.

Access functions:

  • iconSize() const

  • void setIconSize(const &iconSize)

Notifier signal:

movable : bool

This property holds whether the user can move the toolbar within the toolbar area, or between toolbar areas.

By default, this property is true.

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

Access functions:

  • bool isMovable() const

  • void setMovable(bool movable)

Notifier signal:

See Also

See also allowedAreas

orientation : Qt::Orientation

orientation of the toolbar

The default is Qt::Horizontal.

This function should not be used when the toolbar is managed by QMainWindow. You can use QMainWindow::addToolBar() or QMainWindow::insertToolBar() if you wish to move a toolbar that is already added to a main window to another Qt::ToolBarArea.

Access functions:

  • orientation() const

  • void setOrientation( orientation)

Notifier signal:

toolButtonStyle : Qt::ToolButtonStyle

This property holds the style of toolbar buttons

This property defines the style of all tool buttons that are added as QActions. Note that if you add a QToolButton with the addWidget() method, it will not get this button style.

To have the style of toolbuttons follow the system settings, set this property to Qt::ToolButtonFollowStyle. On Unix, the user settings from the desktop environment will be used. On other platforms, Qt::ToolButtonFollowStyle means icon only.

The default is Qt::ToolButtonIconOnly.

Access functions:

  • toolButtonStyle() const

  • void setToolButtonStyle( toolButtonStyle)

Notifier signal:

Member Function Documentation

 

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

Constructs a QToolBar with the given parent.

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

See Also

See also setWindowTitle()

[explicit] QToolBar::QToolBar(QWidget *parent = nullptr)

Constructs a QToolBar with the given parent.

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

See Also

See also QWidget::childAt()

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

This is an overloaded function.

Returns the action at the point x, y. This function returns zero if no action was found.

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

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.

QAction *QToolBar::addSeparator()

Adds a separator to the end of the toolbar.

See Also

See also insertSeparator()

QAction *QToolBar::addWidget(QWidget *widget)

Adds the given widget to the toolbar as the toolbar's last item.

The toolbar takes ownership of widget.

If you add a QToolButton with this method, the toolbar's Qt::ToolButtonStyle will not be respected.

You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.

See Also

See also insertWidget()

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.

Notifier signal for property allowedAreas.

See Also

See also allowedAreas

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

void QToolBar::clear()

Removes all actions from the toolbar.

See Also

See also removeAction()

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

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.

Notifier signal for property iconSize.

See Also

QAction *QToolBar::insertSeparator(QAction *before)

Inserts a separator into the toolbar in front of the toolbar item associated with the before action.

See Also

See also addSeparator()

QAction *QToolBar::insertWidget(QAction *before, QWidget *widget)

Inserts the given widget in front of the toolbar item associated with the before action.

Note: You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.

See Also

See also addWidget()

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

Returns true if this toolbar is dockable in the given area; otherwise returns false.

void QToolBar::movableChanged(bool movable)

This signal is emitted when the toolbar becomes movable or fixed. If the toolbar can be moved, movable is true; otherwise it is false.

Notifier signal for property movable.

See Also

See also movable

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.

Notifier signal for property orientation.

See Also

See also orientation

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

QAction *QToolBar::toggleViewAction() const

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

The action's text is set to the toolbar's window title.

See Also

void QToolBar::toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)

This signal is emitted when the tool button style is changed. The toolButtonStyle parameter holds the toolbar's new tool button style.

Notifier signal for property toolButtonStyle.

See Also

void QToolBar::topLevelChanged(bool topLevel)

This signal is emitted when the floating property changes. The topLevel parameter is true if the toolbar is now floating; otherwise it is false.

See Also

See also isWindow()

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.

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

Returns the widget associated with the specified action.

See Also

See also addWidget()

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+