On this page

Utils::StyledBar Class

class Utils::StyledBar

The StyledBar class is a panel widget for tool bars. More...

Header: #include <utils/widgets.h>
Inherits: QWidget

Public Functions

void addItem(const Utils::Key &id, const QString &displayName, QWidget *widget)
void addSeparator(const Utils::Key &id)
void addSpacer(const Utils::Key &id)
void addStretch(const Utils::Key &id)
Utils::KeyList hiddenItems() const
Utils::StyledBarItemGroup *itemGroup() const
Utils::KeyList itemOrder() const
void resetItemConfiguration()
void setHiddenItems(const Utils::KeyList &ids)
void setItemGroup(Utils::StyledBarItemGroup *group, const Utils::Key &before = {})
void setItemOrder(const Utils::KeyList &ids)
void setItemStretch(const Utils::Key &id, int stretch)
void setItemVisible(const Utils::Key &id, bool visible)
void setPermanentItems(const Utils::KeyList &ids)
void setSettingsKey(const Utils::Key &key)

Static Public Members

void addCustomizationActions(QMenu *menu, const QWidget *item)

Detailed Description

Widgets added with addItem() are laid out by the bar itself. The user can then change their order and hide them in the customization dialog that the context menu of the bar opens, except for the items passed to setPermanentItems(). Use setItemVisible() instead of QWidget::setVisible() to show or hide such items from code. In the customization dialog, the user can also add any number of separators, fixed-width spacers, and stretches. Hiding them removes them again. With setSettingsKey(), the configuration is stored in the user settings.

Like QToolBar, the bar moves the trailing items that do not fit into a popup that an extension button at its end opens. Permanent items always stay in the bar.

Member Function Documentation

[static] void StyledBar::addCustomizationActions(QMenu *menu, const QWidget *item)

Adds the actions that customize and reset the bar that shows item to menu. Use this in the context menu of an item that does not pass the context menu event on to the bar.

void StyledBar::addItem(const Utils::Key &id, const QString &displayName, QWidget *widget)

Adds widget with the identifier id to the end of the bar. The user sees it as displayName when configuring the bar.

void StyledBar::addSeparator(const Utils::Key &id)

Adds a separator with the identifier id to the end of the bar. The user can move and hide it in the toolbar customization dialog.

void StyledBar::addSpacer(const Utils::Key &id)

Adds a fixed-width space with the identifier id to the end of the bar. The user can move and hide it in the toolbar customization dialog.

void StyledBar::addStretch(const Utils::Key &id)

Adds a stretchable space with the identifier id to the end of the bar. The user can move it, but not hide it.

Utils::KeyList StyledBar::hiddenItems() const

Returns the identifiers of the hidden items.

See also setHiddenItems().

Utils::StyledBarItemGroup *StyledBar::itemGroup() const

Returns the group whose items the bar shows, if any.

See also setItemGroup().

Utils::KeyList StyledBar::itemOrder() const

Returns the identifiers of all items in the order in which they appear in the bar, including hidden ones.

See also setItemOrder().

void StyledBar::resetItemConfiguration()

Restores the order in which the items were added and shows all of them.

void StyledBar::setHiddenItems(const Utils::KeyList &ids)

Hides the items with the identifiers ids, except for permanent ones.

See also hiddenItems().

void StyledBar::setItemGroup(Utils::StyledBarItemGroup *group, const Utils::Key &before = {})

Shows the items of group in the bar, in front of the item before, or at the end if before is empty. The items of a group shown before are removed from the bar. Pass nullptr to only remove them.

The bar follows the items of the group as they are added, removed, shown, or hidden. A group is shown by at most one bar at a time; showing it in another bar removes it from this one.

The configuration of the user covers the items of all groups that were shown in bars with the same settings key, so each item keeps its place while it is absent.

See also itemGroup().

void StyledBar::setItemOrder(const Utils::KeyList &ids)

Orders the items as given by ids. Unknown identifiers are ignored, items missing from ids are placed after their predecessor in the order in which they were added.

Separators and spacers added by the user are the exception: an unknown identifier with their prefix creates a new one, and those missing from ids are removed from the bar.

See also itemOrder().

void StyledBar::setItemStretch(const Utils::Key &id, int stretch)

Sets the stretch factor of the item id to stretch. As in QBoxLayout, once an item has a stretch factor, extra space goes to the items with one, in proportion to their factors. Items of a group cannot have a stretch factor.

void StyledBar::setItemVisible(const Utils::Key &id, bool visible)

Shows or hides the item id depending on visible. An item the user has hidden stays hidden. For an item of the group shown in the bar, this is passed on to the group.

void StyledBar::setPermanentItems(const Utils::KeyList &ids)

Prevents the user from hiding the items with the identifiers ids.

void StyledBar::setSettingsKey(const Utils::Key &key)

Restores the item configuration from the user settings at key and stores it there on every change. Call this after adding the items.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.