1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-12-30 18:51:19 +01:00

refactor(colormap_widget): widget is rounded

This commit is contained in:
2025-05-02 15:24:01 +02:00
parent fff4af2489
commit 02563b10f3

View File

@@ -1,4 +1,5 @@
from pyqtgraph.widgets.ColorMapButton import ColorMapButton
from qtpy import QtCore, QtGui
from qtpy.QtCore import Property, Signal, Slot
from qtpy.QtWidgets import QSizePolicy, QVBoxLayout, QWidget
@@ -6,6 +7,23 @@ from bec_widgets.utils import Colors
from bec_widgets.utils.bec_widget import BECWidget
class RoundedColorMapButton(ColorMapButton):
"""Thin wrapper around pyqtgraph ColorMapButton to add rounded clipping."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
def paintEvent(self, evt):
painter = QtGui.QPainter(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
path = QtGui.QPainterPath()
path.addRoundedRect(self.rect(), 8, 8)
painter.setClipPath(path)
self.paintColorMap(painter, self.contentsRect())
painter.end()
class BECColorMapWidget(BECWidget, QWidget):
colormap_changed_signal = Signal(str)
ICON_NAME = "palette"
@@ -15,7 +33,7 @@ class BECColorMapWidget(BECWidget, QWidget):
def __init__(self, parent=None, cmap: str = "plasma", **kwargs):
super().__init__(parent=parent, **kwargs)
# Create the ColorMapButton
self.button = ColorMapButton()
self.button = RoundedColorMapButton()
# Set the size policy and minimum width
size_policy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)