pyqtribbon.ribbonbar module

class pyqtribbon.ribbonbar.RibbonBar(title: str = 'Ribbon Bar Title', maxRows=6, parent=None)[source]
class pyqtribbon.ribbonbar.RibbonBar(parent=None)

Bases: QMenuBar

The RibbonBar class is the top level widget that contains the ribbon.

Create a new ribbon.

Parameters:
  • title – The title of the ribbon.

  • maxRows – The maximum number of rows.

  • parent – The parent widget of the ribbon.

actionAt(self, a0: QPoint) QAction | None[source]
actionGeometry(self, a0: QAction | None) QRect[source]
activeAction(self) QAction | None[source]
addAction(self, action: QAction | None)[source]
addAction(self, text: str | None) QAction | None
addAction(self, text: str | None, slot: PYQT_SLOT) QAction | None
addCategoriesBy(data: Dict[str, Dict]) Dict[str, RibbonCategory][source]

Add categories from a dict.

Parameters:

data

The dict of categories. The dict is of the form:

{
    "category-title": {
        "style": RibbonCategoryStyle.Normal,
        "color": QtCore.Qt.red,
        "panels": {
            "panel-title": {
                "showPanelOptionButton": True,
                "widgets": {
                    "widget-name": {
                        "type": "Button",
                        "args": (),
                        "kwargs": {  # or "arguments" for backward compatibility
                            "key1": "value1",
                            "key2": "value2"
                        }
                    },
                }
            },
        },
    }
}

Returns:

A dict of categories of the ribbon.

addCategory(title: str, style=RibbonCategoryStyle.Normal, color: QColor | None = None) RibbonNormalCategory | RibbonContextCategory[source]

Add a new category to the ribbon.

Parameters:
  • title – The title of the category.

  • style – The button style of the category.

  • color – The color of the context category, only used if style is Context, if None, the default color will be used.

Returns:

The newly created category.

addContextCategories(name: str, titles: List[str], color: QColor | GlobalColor = 9) RibbonContextCategories[source]

Add a group of context categories with the same tab color to the ribbon.

Parameters:
  • name – The name of the context categories.

  • titles – The title of the category.

  • color – The color of the context category, if None, the default color will be used.

Returns:

The newly created category.

addContextCategory(title: str, color: QColor | GlobalColor = 9) RibbonContextCategory[source]

Add a new context category to the ribbon.

Parameters:
  • title – The title of the category.

  • color – The color of the context category, if None, the default color will be used.

Returns:

The newly created category.

addFileMenu() RibbonMenu[source]

Add a file menu to the ribbon.

addMenu(self, menu: QMenu | None) QAction | None[source]
addMenu(self, title: str | None) QMenu | None
addMenu(self, icon: QIcon, title: str | None) QMenu | None
addNormalCategory(title: str) RibbonNormalCategory[source]

Add a new category to the ribbon.

Parameters:

title – The title of the category.

Returns:

The newly created category.

addQuickAccessButton(button: QToolButton)[source]

Add a button to the quick access bar.

Parameters:

button – The button to add.

addRightToolButton(button: QToolButton)[source]

Add a widget to the right button bar.

Parameters:

button – The button to add.

addSeparator(self) QAction | None[source]
addTitleWidget(widget: QWidget)[source]

Add a widget to the title widget.

Parameters:

widget – The widget to add.

applicationOptionButton() RibbonApplicationButton[source]

Return the application button.

autoHideRibbon() bool[source]

Return whether the ribbon bar is automatically hidden when the mouse is pressed outside the ribbon bar.

Returns:

Whether the ribbon bar is automatically hidden.

categories() Dict[str, RibbonCategory][source]

Return a list of categories of the ribbon.

Returns:

A dict of categories of the ribbon.

category(name: str) RibbonCategory[source]

Return the category with the given name.

Parameters:

name – The name of the category.

Returns:

The category with the given name.

categoryVisible(category: RibbonCategory) bool[source]

Return whether the category is shown.

Parameters:

category – The category to check.

Returns:

Whether the category is shown.

clear(self)[source]
collapseRibbonButton() QToolButton[source]

Return the collapse ribbon button.

Returns:

The collapse ribbon button.

cornerWidget(self, corner: Corner = Qt.TopRightCorner) QWidget | None[source]
currentCategory() RibbonCategory[source]

Return the current category.

Returns:

The current category.

eventFilter(self, a0: QObject | None, a1: QEvent | None) bool[source]
helpButtonClicked(bool)[source]

Signal, the help button was clicked.

helpRibbonButton() QToolButton[source]

Return the help button of the ribbon.

Returns:

The help button of the ribbon.

hideContextCategory(category: RibbonContextCategory | RibbonContextCategories)[source]

Hide the given category or categories, if it is not a context category, nothing happens.

Parameters:

category – The category to hide.

hideRibbon()[source]

Hide the ribbon.

insertMenu(self, before: QAction | None, menu: QMenu | None) QAction | None[source]
insertSeparator(self, before: QAction | None) QAction | None[source]
insertTitleWidget(index: int, widget: QWidget)[source]

Insert a widget to the title widget.

Parameters:
  • index – The index to insert the widget.

  • widget – The widget to insert.

isDefaultUp(self) bool[source]
isNativeMenuBar(self) bool[source]
minimumSizeHint() QSize[source]

Return the minimum size hint of the widget.

Returns:

The minimum size hint.

quickAccessToolBar() QToolBar[source]

Return the quick access toolbar of the ribbon.

Returns:

The quick access toolbar of the ribbon.

removeCategories(categories: RibbonContextCategories)[source]

Remove a list of categories from the ribbon.

Parameters:

categories – The categories to remove.

removeCategory(category: RibbonCategory)[source]

Remove a category from the ribbon.

Parameters:

category – The category to remove.

removeCollapseButton()[source]

Remove the min button from the ribbon.

removeHelpButton()[source]

Remove the help button from the ribbon.

removeTitleWidget(widget: QWidget)[source]

Remove a widget from the title widget.

Parameters:

widget – The widget to remove.

ribbonHeight() int[source]

Get the total height of the ribbon.

Returns:

The height of the ribbon.

ribbonVisible() bool[source]

Get the visibility of the ribbon.

Returns:

True if the ribbon is visible, False otherwise.

rightToolBar() QToolBar[source]

Return the right toolbar of the ribbon.

Returns:

The right toolbar of the ribbon.

setActiveAction(self, action: QAction | None)[source]
setApplicationIcon(icon: QIcon)[source]

Set the application icon.

Parameters:

icon – The icon to set.

setAutoHideRibbon(autoHide: bool)[source]

Set whether the ribbon bar is automatically hidden when the mouse is pressed outside the ribbon bar.

Parameters:

autoHide – Whether the ribbon bar is automatically hidden.

setCollapseButtonIcon(icon: QIcon)[source]

Set the icon of the min button.

Parameters:

icon – The icon to set.

setCornerWidget(self, widget: QWidget | None, corner: Corner = Qt.TopRightCorner)[source]
setCurrentCategory(category: RibbonCategory)[source]

Set the current category.

Parameters:

category – The category to set.

setDefaultUp(self, a0: bool)[source]
setHelpButtonIcon(icon: QIcon)[source]

Set the icon of the help button.

Parameters:

icon – The icon to set.

setNativeMenuBar(self, nativeMenuBar: bool)[source]
setQuickAccessButtonHeight(height: int)[source]

Set the height of the quick access buttons.

Parameters:

height – The height to set.

setRibbonHeight(height: int)[source]

Set the total height of the ribbon.

Parameters:

height – The height to set.

setRibbonStyle(style: RibbonStyle)[source]

Set the style of the ribbon.

Parameters:

style – The style to set.

setRibbonVisible(visible: bool)[source]

Set the visibility of the ribbon.

Parameters:

visible – True to show the ribbon, False to hide it.

setRightToolBarHeight(height: int)[source]

Set the height of the right buttons.

Parameters:

height – The height to set.

setTitle(title: str)[source]

Set the title of the ribbon.

Parameters:

title – The title to set.

setTitleWidgetHeight(height: int)[source]

Set the height of the title widget.

Parameters:

height – The height to set.

showCategoryByIndex(index: int)[source]

Show category by tab index

Parameters:

index – tab index

showContextCategory(category: RibbonContextCategory | RibbonContextCategories)[source]

Show the given category or categories, if it is not a context category, nothing happens.

Parameters:

category – The category to show.

showRibbon()[source]

Show the ribbon.

tabBar() RibbonTabBar[source]

Return the tab bar of the ribbon.

Returns:

The tab bar of the ribbon.

title() str[source]

Return the title of the ribbon.

Returns:

The title of the ribbon.

class pyqtribbon.ribbonbar.RibbonStackedWidget(parent=None)[source]

Bases: QStackedWidget

Stacked widget that is used to display the ribbon.

Create a new ribbon stacked widget.

Parameters:

parent – The parent widget.