mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
feat: colorbutton next to each curve in the table to be able to set up colors
This commit is contained in:
@ -9,6 +9,8 @@ from pyqtgraph.Qt import QtCore, uic
|
|||||||
|
|
||||||
from bec_lib.core import MessageEndpoints
|
from bec_lib.core import MessageEndpoints
|
||||||
from bec_widgets.qt_utils import Crosshair, Colors
|
from bec_widgets.qt_utils import Crosshair, Colors
|
||||||
|
from pyqtgraph.Qt import QtWidgets
|
||||||
|
from pyqtgraph import ColorButton
|
||||||
|
|
||||||
|
|
||||||
# TODO implement:
|
# TODO implement:
|
||||||
@ -213,12 +215,35 @@ class PlotApp(QWidget):
|
|||||||
plot.addItem(curve_data)
|
plot.addItem(curve_data)
|
||||||
row_labels.append(f"{y_name} ({y_entry}) - {plot_name}")
|
row_labels.append(f"{y_name} ({y_entry}) - {plot_name}")
|
||||||
|
|
||||||
|
# Create a ColorButton and set its color
|
||||||
|
color_btn = ColorButton()
|
||||||
|
color_btn.setColor(color)
|
||||||
|
color_btn.sigColorChanged.connect(
|
||||||
|
lambda btn=color_btn, curve=curve_data: self.change_curve_color(btn, curve)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add the ColorButton as a QWidget to the table
|
||||||
|
color_widget = QtWidgets.QWidget()
|
||||||
|
layout = QtWidgets.QHBoxLayout()
|
||||||
|
layout.addWidget(color_btn)
|
||||||
|
layout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
color_widget.setLayout(layout)
|
||||||
|
|
||||||
|
row = len(row_labels) - 1 # The row index in the table
|
||||||
|
self.tableWidget_crosshair.setCellWidget(row, 2, color_widget)
|
||||||
|
|
||||||
self.curves_data[plot_name] = curve_list
|
self.curves_data[plot_name] = curve_list
|
||||||
|
|
||||||
self.tableWidget_crosshair.setRowCount(len(row_labels))
|
self.tableWidget_crosshair.setRowCount(len(row_labels))
|
||||||
self.tableWidget_crosshair.setVerticalHeaderLabels(row_labels)
|
self.tableWidget_crosshair.setVerticalHeaderLabels(row_labels)
|
||||||
self.hook_crosshair()
|
self.hook_crosshair()
|
||||||
|
|
||||||
|
def change_curve_color(self, btn, curve):
|
||||||
|
"""Change the color of a curve."""
|
||||||
|
color = btn.color()
|
||||||
|
pen_curve = mkPen(color=color, width=2, style=QtCore.Qt.DashLine)
|
||||||
|
curve.setPen(pen_curve)
|
||||||
|
|
||||||
def hook_crosshair(self):
|
def hook_crosshair(self):
|
||||||
"""Attach crosshairs to each plot and connect them to the update_table method."""
|
"""Attach crosshairs to each plot and connect them to the update_table method."""
|
||||||
self.crosshairs = {}
|
self.crosshairs = {}
|
||||||
|
@ -53,6 +53,11 @@
|
|||||||
<string>Clicked</string>
|
<string>Clicked</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Color</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Reference in New Issue
Block a user