KToolBar Class

Floatable toolbar with auto resize. More...

Header: #include <KToolBar>
CMake: find_package(KF6 REQUIRED COMPONENTS XmlGui)
target_link_libraries(mytarget PRIVATE KF6::XmlGui)
Inherits: QToolBar

Public Functions

KToolBar(QWidget *parent, bool isMainToolBar = false, bool readConfig = true)
KToolBar(const QString &objectName, QWidget *parent, bool readConfig = true)
KToolBar(const QString &objectName, QMainWindow *parentWindow, Qt::ToolBarArea area, bool newLine = false, bool isMainToolBar = false, bool readConfig = true)
virtual ~KToolBar() override
(since 4.8.1) void addXMLGUIClient(KXMLGUIClient *client)
void applySettings(const KConfigGroup &cg)
int iconSizeDefault() const
void loadState(const QDomElement &element)
KMainWindow *mainWindow() const
(since 4.8.5) void removeXMLGUIClient(KXMLGUIClient *client)
void saveSettings(KConfigGroup &cg)
void saveState(QDomElement &element) const
void setIconDimensions(int size)

Reimplemented Public Functions

virtual bool eventFilter(QObject *watched, QEvent *event) override

Static Public Members

(since 5.0) void emitToolbarStyleChanged()
void setToolBarsEditable(bool editable)
void setToolBarsLocked(bool locked)
bool toolBarsEditable()
bool toolBarsLocked()

Detailed Description

A KDE-style toolbar.

KToolBar can be used as a standalone widget, but KMainWindow provides easy factories and management of one or more toolbars.

KToolBar uses a global config group to load toolbar settings on construction. It will reread this config group on a KApplication::appearanceChanged() signal.

KToolBar respects Kiosk settings (see the KAuthorized namespace in the KConfig framework). In particular, system administrators can prevent users from moving toolbars with the "movable_toolbars" action, and from showing or hiding toolbars with the "options_show_toolbar" action. For example, to disable both, add the following the application or global configuration:

[KDE Action Restrictions][$i]
movable_toolbars=false
options_show_toolbar=false

If you can't depend on KXmlGui but still want to integrate better with KDE, you can use QToolBar and:

  • Set ToolButtonStyle to Qt::ToolButtonFollowStyle, this will make QToolBar use the settings for "Main Toolbar".
  • Additionally set QToolBar::setProperty("otherToolbar", true) to use settings for "Other toolbars"; settings from "Other toolbars" will only work on widget styles derived from KStyle.

Member Function Documentation

[explicit] KToolBar::KToolBar(QWidget *parent, bool isMainToolBar = false, bool readConfig = true)

Constructor.

This constructor takes care of adding the toolbar to the mainwindow, if parent is a QMainWindow.

Normally KDE applications do not call this directly, they either call KMainWindow::toolBar(), or they use XML-GUI and specify toolbars using XML.

parent The standard toolbar parent (usually a KMainWindow).

isMainToolBar True for the "main toolbar", false for other toolbars. Different settings apply.

readConfig Whether to apply the configuration (global and application-specific)

[explicit] KToolBar::KToolBar(const QString &objectName, QWidget *parent, bool readConfig = true)

Constructor.

This constructor takes care of adding the toolbar to the mainwindow, if parent is a QMainWindow.

Normally KDE applications do not call this directly, they either call KMainWindow::toolBar(), or they use XML-GUI and specify toolbars using XML.

objectName The QObject name of this toolbar, required so that QMainWindow can save and load the toolbar position, and so that KToolBar can find out if it's the main toolbar.

parent The standard toolbar parent (usually a KMainWindow).

readConfig Whether to apply the configuration (global and application-specific).

KToolBar::KToolBar(const QString &objectName, QMainWindow *parentWindow, Qt::ToolBarArea area, bool newLine = false, bool isMainToolBar = false, bool readConfig = true)

Alternate constructor with additional arguments, e.g. to choose in which area the toolbar should be auto-added. This is rarely used in KDE. When using XMLGUI you can specify this as an xml attribute instead.

objectName The QObject name of this toolbar, required so that QMainWindow can save and load the toolbar position.

parentWindow The window that should be the parent of this toolbar.

area The position of the toolbar. Usually Qt::TopToolBarArea.

newLine If true, start a new line in the dock for this toolbar.

isMainToolBar True for the "main toolbar", false for other toolbars. Different settings apply. readConfig whether to apply the configuration (global and application-specific)

[override virtual noexcept] KToolBar::~KToolBar()

Destroys the toolbar.

[since 4.8.1] void KToolBar::addXMLGUIClient(KXMLGUIClient *client)

Adds an XML gui client that uses this toolbar.

This function was introduced in 4.8.1.

void KToolBar::applySettings(const KConfigGroup &cg)

Read the toolbar settings from group cg and apply them.

[static, since 5.0] void KToolBar::emitToolbarStyleChanged()

Emits a D-Bus signal to tell all toolbars in all applications that the user settings have changed.

This function was introduced in 5.0.

[override virtual] bool KToolBar::eventFilter(QObject *watched, QEvent *event)

Reimplements: QObject::eventFilter(QObject *watched, QEvent *event).

Filters then returns the specified event for a given watched object.

Reimplemented to support context menu activation on disabled tool buttons.

int KToolBar::iconSizeDefault() const

Returns the default size for this type of toolbar.

void KToolBar::loadState(const QDomElement &element)

Load state from an XML element, called by KXMLGUIBuilder.

KMainWindow *KToolBar::mainWindow() const

Returns the main window that this toolbar is docked with.

[since 4.8.5] void KToolBar::removeXMLGUIClient(KXMLGUIClient *client)

Removes an XML gui client that uses this toolbar.

This function was introduced in 4.8.5.

void KToolBar::saveSettings(KConfigGroup &cg)

Save the toolbar settings to group cg.

void KToolBar::saveState(QDomElement &element) const

Save state into an XML element, called by KXMLGUIBuilder.

void KToolBar::setIconDimensions(int size)

Convenience function to set icon size.

[static] void KToolBar::setToolBarsEditable(bool editable)

Makes all toolbars editable via drag & drop of actions.

This is called by KEditToolBar and should generally be set to disabled whenever KEditToolBar is not active.

See also toolBarsEditable().

[static] void KToolBar::setToolBarsLocked(bool locked)

Makes all toolbars locked (that is, disallow/allow moving of the toolbars).

See also toolBarsLocked().

[static] bool KToolBar::toolBarsEditable()

Returns whether the toolbars are currently editable (drag & drop of actions).

See also setToolBarsEditable().

[static] bool KToolBar::toolBarsLocked()

Returns whether the toolbars are locked (that is, disallow moving of the toolbars).

See also setToolBarsLocked().