msl.qt.widgets.button module

A QToolButton to display text, an icon and a menu.

class msl.qt.widgets.button.Button(*, text=None, icon=None, icon_size=None, left_click=None, right_click=None, is_text_under_icon=True, tooltip=None, parent=None)[source]

Bases: QToolButton

A QToolButton to display text, an icon and a menu.

Parameters:
  • text (str, optional) – The text to display on the button.
  • icon (object, optional) – Any icon object that is supported by to_qicon().
  • icon_size (int, float, tuple of int or QtCore.QSize, optional) – Rescale the icon to the specified size. If the value is None then do not rescale the icon. If an int then set the width and the height to be the size value. If a float then a scaling factor. If a tuple then the (width, height) values.
  • left_click (callable, optional) – The function to be called for a mouse left-click event.
  • right_click (callable, optional) – The function to be called for a mouse right-click event.
  • is_text_under_icon (bool, optional) – If displaying an icon and text then whether to place the text under, True, or beside, False, the icon.
  • tooltip (str, optional) – The tooltip to display for the button.
  • parent (QtWidgets.QWidget, optional) – The parent widget.
add_menu_item(*, text=None, triggered=None, icon=None, shortcut=None, tooltip=None)[source]

Add a new item to the action menu.

Parameters:
  • text (str, optional) – The text to display for this item.
  • triggered (callable, optional) – The function to be called when this item is selected. If None then the item is displayed but it is disabled.
  • icon (object, optional) – Any icon object that is supported by to_qicon().
  • shortcut (str, optional) – The keyboard shortcut to use to select this item, e.g., 'CTRL+A'
  • tooltip (str, optional) – The tooltip to display for this item.
add_menu_separator()[source]

Insert a separator between menu items.

set_left_click(fcn)[source]

The function to be called for a mouse left-click event.

Parameters:fcn (callable) – The function to be called for a mouse left-click event.
set_right_click(fcn)[source]

The function to be called for a mouse right-click event.

Parameters:fcn (callable) – The function to be called for a mouse right-click event.
class msl.qt.widgets.button.ButtonMenu[source]

Bases: QMenu

Display the QtWidgets.QMenu underneath the Button.

showEvent(event)[source]

Overrides QtWidgets.QWidget.showEvent().