aboutsummaryrefslogtreecommitdiffstats
path: root/examples/charts/legend/legend.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/charts/legend/legend.py')
-rw-r--r--examples/charts/legend/legend.py60
1 files changed, 15 insertions, 45 deletions
diff --git a/examples/charts/legend/legend.py b/examples/charts/legend/legend.py
index 2996904c8..5417a940f 100644
--- a/examples/charts/legend/legend.py
+++ b/examples/charts/legend/legend.py
@@ -1,50 +1,14 @@
-#############################################################################
-##
-## Copyright (C) 2021 The Qt Company Ltd.
-## Contact: http://www.qt.io/licensing/
-##
-## This file is part of the Qt for Python examples of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## You may use this file under the terms of the BSD license as follows:
-##
-## "Redistribution and use in source and binary forms, with or without
-## modification, are permitted provided that the following conditions are
-## met:
-## * Redistributions of source code must retain the above copyright
-## notice, this list of conditions and the following disclaimer.
-## * Redistributions in binary form must reproduce the above copyright
-## notice, this list of conditions and the following disclaimer in
-## the documentation and/or other materials provided with the
-## distribution.
-## * Neither the name of The Qt Company Ltd nor the names of its
-## contributors may be used to endorse or promote products derived
-## from this software without specific prior written permission.
-##
-##
-## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
"""PySide6 port of the Legend example from Qt v5.x"""
import sys
-from PySide6.QtCore import Qt, QRectF
+from PySide6.QtCore import Qt, QRectF, Slot
from PySide6.QtGui import QBrush, QColor, QPainter, QPen
from PySide6.QtWidgets import (QApplication, QDoubleSpinBox,
- QFormLayout, QGridLayout, QGroupBox, QPushButton, QWidget)
+ QFormLayout, QGridLayout, QGroupBox,
+ QPushButton, QWidget)
from PySide6.QtCharts import QBarSeries, QBarSet, QChart, QChartView
@@ -160,6 +124,7 @@ class MainWidget(QWidget):
def hide_legend_spinbox(self):
self.legend_settings.setVisible(False)
+ @Slot()
def toggle_attached(self):
legend = self.chart.legend()
if legend.isAttachedToChart():
@@ -176,6 +141,7 @@ class MainWidget(QWidget):
self.hide_legend_spinbox()
self.update()
+ @Slot()
def add_barset(self):
series_count = self.series.count()
bar_set = QBarSet(f"set {series_count}")
@@ -183,12 +149,14 @@ class MainWidget(QWidget):
bar_set.append([1 + delta, 2 + delta, 3 + delta, 4 + delta])
self.series.append(bar_set)
+ @Slot()
def remove_barset(self):
sets = self.series.barSets()
len_sets = len(sets)
if len_sets > 0:
self.series.remove(sets[len_sets - 1])
+ @Slot()
def set_legend_alignment(self):
button = self.sender()
legend = self.chart.legend()
@@ -211,18 +179,21 @@ class MainWidget(QWidget):
button.setText("Align (Top)")
legend.setAlignment(Qt.AlignTop)
+ @Slot()
def toggle_bold(self):
legend = self.chart.legend()
font = legend.font()
font.setBold(not font.bold())
legend.setFont(font)
+ @Slot()
def toggle_italic(self):
legend = self.chart.legend()
font = legend.font()
font.setItalic(not font.italic())
legend.setFont(font)
+ @Slot()
def font_size_changed(self):
legend = self.chart.legend()
font = legend.font()
@@ -232,13 +203,12 @@ class MainWidget(QWidget):
font.setPointSizeF(font_size)
legend.setFont(font)
+ @Slot()
def update_legend_layout(self):
legend = self.chart.legend()
- rect = QRectF(self.legend_posx.value(),
- self.legend_posy.value(),
- self.legend_width.value(),
- self.legend_height.value())
+ rect = QRectF(self.legend_posx.value(), self.legend_posy.value(),
+ self.legend_width.value(), self.legend_height.value())
legend.setGeometry(rect)
legend.update()