aboutsummaryrefslogtreecommitdiffstats
path: root/examples/charts/pointselectionandmarkers
diff options
context:
space:
mode:
Diffstat (limited to 'examples/charts/pointselectionandmarkers')
-rw-r--r--examples/charts/pointselectionandmarkers/doc/pointselectionandmarkers.rst12
-rw-r--r--examples/charts/pointselectionandmarkers/pointselectionandmarkers.py27
-rw-r--r--examples/charts/pointselectionandmarkers/pointselectionandmarkers.pyproject2
-rw-r--r--examples/charts/pointselectionandmarkers/utilities.py12
4 files changed, 32 insertions, 21 deletions
diff --git a/examples/charts/pointselectionandmarkers/doc/pointselectionandmarkers.rst b/examples/charts/pointselectionandmarkers/doc/pointselectionandmarkers.rst
index cf8b9a264..e8776daf8 100644
--- a/examples/charts/pointselectionandmarkers/doc/pointselectionandmarkers.rst
+++ b/examples/charts/pointselectionandmarkers/doc/pointselectionandmarkers.rst
@@ -18,7 +18,7 @@ Creating the chart and its elements
We start by creating a series, filling it with the data, and enabling the light marker and point selection features.
It is important not to set points visibility to :py:`True`, because light markers functionality is an independent feature and setting both would result in undesired behavior.
-.. literalinclude:: ../../../../examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
+.. literalinclude:: pointselectionandmarkers.py
:linenos:
:lineno-start: 20
:lines: 20-42
@@ -26,7 +26,7 @@ It is important not to set points visibility to :py:`True`, because light marker
Then we create the :py:`QChart`, the :py:`QChartview` and the control widget with its layout to arrange customization elements.
-.. literalinclude:: ../../../../examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
+.. literalinclude:: pointselectionandmarkers.py
:lineno-start: 44
:lines: 44-53
:emphasize-lines: 1,6,9
@@ -36,7 +36,7 @@ Creating UI for configuring the chart
The next step is where we create user interface elements that allow customizing the chart, including setting light marker and selection marker images.
-.. literalinclude:: ../../../../examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
+.. literalinclude:: pointselectionandmarkers.py
:linenos:
:lineno-start: 54
:lines: 54-57
@@ -44,7 +44,7 @@ The next step is where we create user interface elements that allow customizing
We create the label for the marker selection combobox and fill the combobox with the items. We then provide functionality to the combobox, allowing the user's selection to set the desired light marker image. As light markers are enabled and disabled by setting a valid QImage or setting an empty :py:`QImage()`, we need to make sure that if the user does not wish unselected points to be displayed, we do not actually set the light marker image.
If checking isn't performed, a new :py:`QImage` will be set as the light marker and unselected points will be visible even though it has been switched off.
-.. literalinclude:: ../../../../examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
+.. literalinclude:: pointselectionandmarkers.py
:linenos:
:lineno-start: 59
:lines: 59-67
@@ -52,14 +52,14 @@ If checking isn't performed, a new :py:`QImage` will be set as the light marker
Almost the same procedure applies to the selected point light marker and line color. The only difference is that there is no need to check the visibility of unselected points as it doesn't affect the functionality.
-.. literalinclude:: ../../../../examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
+.. literalinclude:: pointselectionandmarkers.py
:linenos:
:lineno-start: 70
:lines: 70-85
A small difference comes with changing visibility of unselected points. As it was mentioned before, making light markers invisible is achieved by setting the light marker to an empty :py:`QImage()`. That is why, depending on checkbox state, selected point light marker is set to an empty :py:`QImage` or to the light marker extracted from the current index of the corresponding combobox.
-.. literalinclude:: ../../../../examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
+.. literalinclude:: pointselectionandmarkers.py
:linenos:
:lineno-start: 88
:lines: 88-97
diff --git a/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py b/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
index 4f9540d42..df7b61687 100644
--- a/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
+++ b/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py
@@ -7,7 +7,8 @@ import sys
from PySide6.QtCore import Slot, QPointF, Qt
from PySide6.QtCharts import QChart, QChartView, QSplineSeries
from PySide6.QtGui import QPainter, QImage
-from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout, QComboBox, QCheckBox, QLabel, QHBoxLayout
+from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QGridLayout,
+ QComboBox, QCheckBox, QLabel, QHBoxLayout)
import utilities as Utilities
@@ -20,12 +21,12 @@ if __name__ == "__main__":
marker_size = 20.
series = QSplineSeries()
series.append([QPointF(0, 0),
- QPointF(0.5, 2.27),
- QPointF(1.5, 2.2),
- QPointF(3.3, 1.7),
- QPointF(4.23, 3.1),
- QPointF(5.3, 2.3),
- QPointF(6.47, 4.1)])
+ QPointF(0.5, 2.27),
+ QPointF(1.5, 2.2),
+ QPointF(3.3, 1.7),
+ QPointF(4.23, 3.1),
+ QPointF(5.3, 2.3),
+ QPointF(6.47, 4.1)])
series.setMarkerSize(marker_size)
series.setLightMarker(Utilities.default_light_marker(marker_size))
series.setSelectedLightMarker(Utilities.default_selected_light_marker(marker_size))
@@ -66,16 +67,16 @@ if __name__ == "__main__":
char_point_combobox.addItems(["Red rectangle", "Green triangle", "Orange circle"])
char_point_combobox.currentIndexChanged.connect(set_light_marker)
-
@Slot(int)
def set_selected_light_marker(index):
- series.setSelectedLightMarker(Utilities.get_selected_point_representation(Utilities.selected_point_type(index), marker_size))
+ series.setSelectedLightMarker(
+ Utilities.get_selected_point_representation(
+ Utilities.selected_point_type(index), marker_size))
char_point_selected = QLabel("Char point selected: ")
char_point_selected_combobox.addItems(["Blue triangle", "Yellow rectangle", "Lavender circle"])
char_point_selected_combobox.currentIndexChanged.connect(set_selected_light_marker)
-
@Slot(int)
def set_line_color(index):
series.setColor(Utilities.make_line_color(Utilities.line_color(index)))
@@ -84,11 +85,12 @@ if __name__ == "__main__":
line_color_combobox.addItems(["Blue", "Black", "Mint"])
line_color_combobox.currentIndexChanged.connect(set_line_color)
-
@Slot(int)
def display_unselected_points(checkbox_state):
if checkbox_state:
- series.setLightMarker(Utilities.get_point_representation(Utilities.point_type(char_point_combobox.currentIndex()), marker_size))
+ series.setLightMarker(
+ Utilities.get_point_representation(
+ Utilities.point_type(char_point_combobox.currentIndex()), marker_size))
else:
series.setLightMarker(QImage())
@@ -96,7 +98,6 @@ if __name__ == "__main__":
show_unselected_points_checkbox.setChecked(True)
show_unselected_points_checkbox.stateChanged.connect(display_unselected_points)
-
control_label = QLabel("Marker and Selection Controls")
control_label.setAlignment(Qt.AlignHCenter)
control_label_font = control_label.font()
diff --git a/examples/charts/pointselectionandmarkers/pointselectionandmarkers.pyproject b/examples/charts/pointselectionandmarkers/pointselectionandmarkers.pyproject
index 499a3bd3c..8c394457c 100644
--- a/examples/charts/pointselectionandmarkers/pointselectionandmarkers.pyproject
+++ b/examples/charts/pointselectionandmarkers/pointselectionandmarkers.pyproject
@@ -1,3 +1,3 @@
{
- "files": ["pointselectionandmarkers.py", "utilities.py", "markers.qrc", "rc_markers.py"]
+ "files": ["pointselectionandmarkers.py", "utilities.py", "markers.qrc"]
}
diff --git a/examples/charts/pointselectionandmarkers/utilities.py b/examples/charts/pointselectionandmarkers/utilities.py
index 6b96d6e26..b27a2542b 100644
--- a/examples/charts/pointselectionandmarkers/utilities.py
+++ b/examples/charts/pointselectionandmarkers/utilities.py
@@ -4,7 +4,8 @@
from PySide6.QtGui import QImage, QPainter, QColor
from PySide6.QtCore import Qt
-import rc_markers
+import rc_markers # noqa: F401
+
def rectangle(point_type, image_size):
image = QImage(image_size, image_size, QImage.Format_RGB32)
@@ -15,9 +16,11 @@ def rectangle(point_type, image_size):
painter.end()
return image
+
def triangle(point_type, image_size):
return QImage(point_type[3]).scaled(image_size, image_size)
+
def circle(point_type, image_size):
image = QImage(image_size, image_size, QImage.Format_ARGB32)
image.fill(QColor(0, 0, 0, 0))
@@ -32,6 +35,7 @@ def circle(point_type, image_size):
painter.end()
return image
+
_point_types = [("RedRectangle", rectangle, Qt.red),
("GreenTriangle", triangle, Qt.green, ":/images/green_triangle.png"),
("OrangeCircle", circle, QColor(255, 127, 80))]
@@ -40,12 +44,15 @@ _selected_point_types = [("BlueTriangle", triangle, Qt.blue, ":/images/blue_tria
("LavenderCircle", circle, QColor(147, 112, 219))]
_line_colors = [("Blue", QColor(65, 105, 225)), ("Black", Qt.black), ("Mint", QColor(70, 203, 155))]
+
def point_type(index):
return _point_types[index]
+
def selected_point_type(index):
return _selected_point_types[index]
+
def line_color(index):
return _line_colors[index]
@@ -53,6 +60,7 @@ def line_color(index):
def default_light_marker(image_size):
return rectangle(_point_types[0], image_size)
+
def default_selected_light_marker(image_size):
return triangle(_selected_point_types[0], image_size)
@@ -60,8 +68,10 @@ def default_selected_light_marker(image_size):
def get_point_representation(point_type, image_size):
return point_type[1](point_type, image_size)
+
def get_selected_point_representation(point_type, image_size):
return point_type[1](point_type, image_size)
+
def make_line_color(line_color):
return line_color[1]