fix(toolbar): create_action_with_text text will not change to tooltip when disable/enable/checked

This commit is contained in:
2025-10-27 19:05:59 +01:00
committed by Jan Wyzula
parent 140f126560
commit 6b5aa74934
2 changed files with 31 additions and 2 deletions
+7 -1
View File
@@ -43,13 +43,19 @@ def create_action_with_text(toolbar_action, toolbar: QToolBar):
"""
btn = QToolButton(parent=toolbar)
if getattr(toolbar_action, "label_text", None):
toolbar_action.action.setText(toolbar_action.label_text)
if getattr(toolbar_action, "tooltip", None):
toolbar_action.action.setToolTip(toolbar_action.tooltip)
btn.setToolTip(toolbar_action.tooltip)
btn.setDefaultAction(toolbar_action.action)
btn.setAutoRaise(True)
if toolbar_action.text_position == "under":
btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
else:
btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
btn.setText(toolbar_action.label_text)
toolbar.addWidget(btn)
+24 -1
View File
@@ -6,7 +6,7 @@ from collections import defaultdict
from typing import DefaultDict, Literal
from bec_lib.logger import bec_logger
from qtpy.QtCore import QSize, Qt
from qtpy.QtCore import QSize, Qt, QTimer
from qtpy.QtGui import QAction, QColor
from qtpy.QtWidgets import QApplication, QLabel, QMainWindow, QMenu, QToolBar, QVBoxLayout, QWidget
@@ -492,10 +492,33 @@ if __name__ == "__main__": # pragma: no cover
self.toolbar.connect_bundle(
"base", PerformanceConnection(self.toolbar.components, self)
)
self.toolbar.components.add_safe(
"text",
MaterialIconAction(
"text_fields",
tooltip="Test Text Action",
checkable=True,
label_text="text",
text_position="under",
),
)
self.toolbar.show_bundles(["performance", "plot_export"])
self.toolbar.get_bundle("performance").add_action("save")
self.toolbar.get_bundle("performance").add_action("text")
self.toolbar.refresh()
# Timer to disable and enable text button each 2s
self.timer = QTimer()
self.timer.timeout.connect(self.toggle_text_action)
self.timer.start(2000)
def toggle_text_action(self):
text_action = self.toolbar.components.get_action("text")
if text_action.action.isEnabled():
text_action.action.setEnabled(False)
else:
text_action.action.setEnabled(True)
def enable_fps_monitor(self, enabled: bool):
"""
Example method to enable or disable FPS monitoring.