def set_enabled_and_raise(action: QAction, value: bool): """Disable or enable the action and autoRaise the associated QToolButton. Parameters ---------- action: QAction The action to enable or disable value: bool True to enable action and raise associated QToolButton. """ action.setEnabled(value) for widget in action.associatedWidgets(): if isinstance(widget, QToolButton): widget.setAutoRaise(not value) # Change background color to pale gray if button is enabled color = "#d7d6d5" if value else "white" widget.setStyleSheet(f"background-color: {color}")