0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

fix(toolbar): change default color to black to match BECFigure theme

This commit is contained in:
2024-07-02 22:13:36 +02:00
committed by wyzula_j
parent 6e75642090
commit b8774e0b0b

View File

@ -2,9 +2,9 @@ from abc import ABC, abstractmethod
from collections import defaultdict
# pylint: disable=no-name-in-module
from qtpy.QtCore import QSize, QTimer
from qtpy.QtCore import QSize
from qtpy.QtGui import QAction
from qtpy.QtWidgets import QApplication, QHBoxLayout, QLabel, QSpinBox, QStyle, QToolBar, QWidget
from qtpy.QtWidgets import QHBoxLayout, QLabel, QSpinBox, QToolBar, QWidget
class ToolBarAction(ABC):
@ -50,19 +50,19 @@ class ModularToolBar(QToolBar):
"""Modular toolbar with optional automatic initialization.
Args:
parent (QWidget, optional): The parent widget of the toolbar. Defaults to None.
auto_init (bool, optional): If True, automatically populates the toolbar based on the parent widget.
actions (list[ToolBarAction], optional): A list of action creators to populate the toolbar. Defaults to None.
target_widget (QWidget, optional): The widget that the actions will target. Defaults to None.
color (str, optional): The background color of the toolbar. Defaults to "black".
"""
def __init__(self, parent=None, actions=None, target_widget=None):
def __init__(self, parent=None, actions=None, target_widget=None, color: str = "black"):
super().__init__(parent)
self.setStyleSheet("QToolBar { background: transparent; }")
self.setIconSize(QSize(20, 20))
self.widgets = defaultdict(dict)
self.set_background_color(color)
if actions is not None and target_widget is not None:
self.populate_toolbar(actions, target_widget)
# QTimer.singleShot(0, lambda :self.set_manual_actions(actions, target_widget))
def populate_toolbar(self, actions: dict, target_widget):
"""Populates the toolbar with a set of actions.
@ -76,19 +76,9 @@ class ModularToolBar(QToolBar):
action.add_to_toolbar(self, target_widget)
self.widgets[action_id] = action
# for action in actions:
# action.add_to_toolbar(self, target_widget)
# def set_manual_actions(self, actions, target_widget):
# """Manually sets the actions for the toolbar.
#
# Args:
# actions (list[QAction or ToolBarAction]): A list of actions or action creators to populate the toolbar.
# target_widget (QWidget): The widget that the actions will target.
# """
# self.clear()
# for action in actions:
# if isinstance(action, QAction):
# self.addAction(action)
# elif isinstance(action, ToolBarAction):
# self.addAction(action.add_to_toolbar(self, target_widget))
def set_background_color(self, color: str):
self.setStyleSheet(f"QToolBar {{ background: {color}; }}")
self.setIconSize(QSize(20, 20))
self.setMovable(False)
self.setFloatable(False)
self.setContentsMargins(0, 0, 0, 0)