diff options
author | Ece Cinucen <[email protected]> | 2025-03-04 15:30:33 +0100 |
---|---|---|
committer | Ece Cinucen <[email protected]> | 2025-03-05 09:56:23 +0100 |
commit | b79beba4247e86095e82d0f082eb540bc63f01cf (patch) | |
tree | d8808db063ec9d72b1d129cffe5c02bbfe0c1a4e | |
parent | 2ccb5f59c76ae4c0c1d9745e8751f99b82c8c15d (diff) |
Example: Update widgetgraphgallery example
Updated according to the Qt example.
Pick-to: 6.8
Change-Id: Id2e64b2ab46ddd25f80ff8cc64bfb13ed02a92c5
Reviewed-by: Friedemann Kleint <[email protected]>
3 files changed, 94 insertions, 54 deletions
diff --git a/examples/graphs/3d/widgetgraphgallery/highlightseries.py b/examples/graphs/3d/widgetgraphgallery/highlightseries.py index 27dad4705..58a0d531b 100644 --- a/examples/graphs/3d/widgetgraphgallery/highlightseries.py +++ b/examples/graphs/3d/widgetgraphgallery/highlightseries.py @@ -26,6 +26,7 @@ class HighlightSeries(QSurface3DSeries): self._position = {} self._topographicSeries = None self._minHeight = 0.0 + self._height_adjustment = 5.0 self.setDrawMode(QSurface3DSeries.DrawFlag.DrawSurface) self.setShading(QSurface3DSeries.Shading.Flat) self.setVisible(False) @@ -72,7 +73,7 @@ class HighlightSeries(QSurface3DSeries): srcRow = srcArray[i] for j in range(startX, endX): pos = srcRow.at(j).position() - pos.setY(pos.y() + 0.1) + pos.setY(pos.y() + self._height_adjustment) item = QSurfaceDataItem(QVector3D(pos)) newRow.append(item) dataArray.append(newRow) @@ -93,3 +94,8 @@ class HighlightSeries(QSurface3DSeries): self.setBaseGradient(gr) self.setColorStyle(QGraphsTheme.ColorStyle.RangeGradient) + + self.handle_zoom_change(ratio) + + def handle_zoom_change(self, zoom): + self._height_adjustment = (1.2 - zoom) * 10.0 diff --git a/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py b/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py index 946c96261..984bf9df2 100644 --- a/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py +++ b/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py @@ -5,7 +5,7 @@ from __future__ import annotations from enum import Enum from math import sin, cos, degrees, sqrt -from PySide6.QtCore import QObject, Signal, Slot, Qt +from PySide6.QtCore import QObject, Signal, Slot, Qt, QRandomGenerator from PySide6.QtGui import QVector2D, QVector3D from PySide6.QtGraphs import (QAbstract3DSeries, QScatterDataItem, QScatterDataProxy, @@ -27,7 +27,7 @@ class InputState(Enum): class ScatterDataModifier(QObject): - backgroundEnabledChanged = Signal(bool) + backgroundVisibleChanged = Signal(bool) gridVisibleChanged = Signal(bool) shadowQualityChanged = Signal(int) @@ -42,11 +42,11 @@ class ScatterDataModifier(QObject): self._itemCount = LOWER_NUMBER_OF_ITEMS self._CURVE_DIVIDER = LOWER_CURVE_DIVIDER - self._graph.activeTheme().setTheme(QGraphsTheme.Theme.MixSeries) - self._graph.activeTheme().setColorScheme(QGraphsTheme.ColorScheme.Dark) self._graph.setShadowQuality(QtGraphs3D.ShadowQuality.SoftHigh) self._graph.setCameraPreset(QtGraphs3D.CameraPreset.Front) self._graph.setCameraZoomLevel(80.0) + self._graph.activeTheme().setTheme(QGraphsTheme.Theme.MixSeries) + self._graph.activeTheme().setColorScheme(QGraphsTheme.ColorScheme.Dark) self._proxy = QScatterDataProxy() self._series = QScatter3DSeries(self._proxy) @@ -99,7 +99,7 @@ class ScatterDataModifier(QObject): def changeTheme(self, theme): currentTheme = self._graph.activeTheme() currentTheme.setTheme(QGraphsTheme.Theme(theme)) - self.backgroundEnabledChanged.emit(currentTheme.isPlotAreaBackgroundVisible()) + self.backgroundVisibleChanged.emit(currentTheme.isPlotAreaBackgroundVisible()) self.gridVisibleChanged.emit(currentTheme.isGridVisible()) @Slot() @@ -114,45 +114,6 @@ class ScatterDataModifier(QObject): def shadowQualityUpdatedByVisual(self, sq): self.shadowQualityChanged.emit(sq.value) - @Slot(int) - def changeShadowQuality(self, quality): - sq = QtGraphs3D.ShadowQuality(quality) - self._graph.setShadowQuality(sq) - - @Slot(int) - def setPlotAreaBackgroundVisible(self, state): - enabled = state == Qt.CheckState.Checked - self._graph.activeTheme().setPlotAreaBackgroundVisible(enabled) - - @Slot(int) - def setGridVisible(self, state): - self._graph.activeTheme().setGridVisible(state == Qt.Checked.value) - - @Slot() - def toggleItemCount(self): - if self._itemCount == NUMBER_OF_ITEMS: - self._itemCount = LOWER_NUMBER_OF_ITEMS - self._CURVE_DIVIDER = LOWER_CURVE_DIVIDER - else: - self._itemCount = NUMBER_OF_ITEMS - self._CURVE_DIVIDER = CURVE_DIVIDER - - self._graph.seriesList()[0].dataProxy().resetArray([]) - self.addData() - - @Slot() - def toggleRanges(self): - if not self._autoAdjust: - self._graph.axisX().setAutoAdjustRange(True) - self._graph.axisZ().setAutoAdjustRange(True) - self._dragSpeedModifier = 1.5 - self._autoAdjust = True - else: - self._graph.axisX().setRange(-10.0, 10.0) - self._graph.axisZ().setRange(-10.0, 10.0) - self._dragSpeedModifier = float(15) - self._autoAdjust = False - @Slot(QtGraphs3D.ElementType) def handleElementSelected(self, type): if type == QtGraphs3D.ElementType.AxisXLabel: @@ -197,3 +158,69 @@ class ScatterDataModifier(QObject): # No need to use adjusted y move here distance = move.y() / self._dragSpeedModifier axis.setRange(axis.min() + distance, axis.max() + distance) + + @Slot(int) + def changeShadowQuality(self, quality): + sq = QtGraphs3D.ShadowQuality(quality) + self._graph.setShadowQuality(sq) + + @Slot(int) + def setBackgroundVisible(self, state): + enabled = state == Qt.CheckState.Checked + self._graph.activeTheme().setPlotAreaBackgroundVisible(enabled) + + @Slot(int) + def setGridVisible(self, state): + self._graph.activeTheme().setGridVisible(state == Qt.Checked.value) + + @Slot() + def toggleItemCount(self): + if self._itemCount == NUMBER_OF_ITEMS: + self._itemCount = LOWER_NUMBER_OF_ITEMS + self._CURVE_DIVIDER = LOWER_CURVE_DIVIDER + else: + self._itemCount = NUMBER_OF_ITEMS + self._CURVE_DIVIDER = CURVE_DIVIDER + + self._graph.seriesList()[0].dataProxy().resetArray([]) + self.addData() + + @Slot() + def toggleRanges(self): + if not self._autoAdjust: + self._graph.axisX().setAutoAdjustRange(True) + self._graph.axisZ().setAutoAdjustRange(True) + self._dragSpeedModifier = 1.5 + self._autoAdjust = True + else: + self._graph.axisX().setRange(-10.0, 10.0) + self._graph.axisZ().setRange(-10.0, 10.0) + self._dragSpeedModifier = float(15) + self._autoAdjust = False + + def adjust_minimum_range(self, range): + if self._itemCount == LOWER_NUMBER_OF_ITEMS: + range *= 1.45 + else: + range *= 4.95 + + self._graph.axisX().setMin(range) + self._graph.axisZ().setMin(range) + self._autoAdjust = False + + def adjust_maximum_range(self, range): + if self._itemCount == LOWER_NUMBER_OF_ITEMS: + range *= 1.45 + else: + range *= 4.95 + + self._graph.axisX().setMax(range) + self._graph.axisZ().setMax(range) + self._autoAdjust = False + + def rand_vector() -> QVector3D: + generator = QRandomGenerator.global_() + x = float(generator.bounded(100)) / 2.0 - float(generator.bounded(100)) / 2.0 + y = float(generator.bounded(100)) / 100.0 - float(generator.bounded(100)) / 100.0 + z = float(generator.bounded(100)) / 2.0 - float(generator.bounded(100)) / 2.0 + return QVector3D(x, y, z) diff --git a/examples/graphs/3d/widgetgraphgallery/scattergraph.py b/examples/graphs/3d/widgetgraphgallery/scattergraph.py index 1b5c507a9..050ce2854 100644 --- a/examples/graphs/3d/widgetgraphgallery/scattergraph.py +++ b/examples/graphs/3d/widgetgraphgallery/scattergraph.py @@ -5,7 +5,7 @@ from __future__ import annotations from PySide6.QtCore import QObject, QSize, Qt from PySide6.QtWidgets import (QCheckBox, QComboBox, QCommandLinkButton, QLabel, QHBoxLayout, QSizePolicy, - QVBoxLayout, QWidget, ) + QVBoxLayout, QWidget, QSlider) from PySide6.QtQuickWidgets import QQuickWidget from PySide6.QtGraphs import QAbstract3DSeries from PySide6.QtGraphsWidgets import Q3DScatterWidgetItem @@ -42,10 +42,15 @@ class ScatterGraph(QObject): itemCountButton.setDescription("Switch between 900 and 10000 data points") itemCountButton.setIconSize(QSize(0, 0)) - rangeButton = QCommandLinkButton(self._scatterWidget) - rangeButton.setText("Toggle axis ranges") - rangeButton.setDescription("Switch between automatic axis ranges and preset ranges") - rangeButton.setIconSize(QSize(0, 0)) + range_min_slider = QSlider(Qt.Horizontal, self._scatterWidget) + range_min_slider.setMinimum(-10) + range_min_slider.setMaximum(1) + range_min_slider.setValue(-10) + + range_max_slider = QSlider(Qt.Horizontal, self._scatterWidget) + range_max_slider.setMinimum(1) + range_max_slider.setMaximum(10) + range_max_slider.setValue(10) backgroundCheckBox = QCheckBox(self._scatterWidget) backgroundCheckBox.setText("Show graph background") @@ -89,7 +94,8 @@ class ScatterGraph(QObject): vLayout.addWidget(cameraButton) vLayout.addWidget(itemCountButton) - vLayout.addWidget(rangeButton) + vLayout.addWidget(range_min_slider) + vLayout.addWidget(range_max_slider) vLayout.addWidget(backgroundCheckBox) vLayout.addWidget(gridCheckBox) vLayout.addWidget(smoothCheckBox) @@ -104,13 +110,14 @@ class ScatterGraph(QObject): cameraButton.clicked.connect(modifier.changePresetCamera) itemCountButton.clicked.connect(modifier.toggleItemCount) - rangeButton.clicked.connect(modifier.toggleRanges) + range_min_slider.valueChanged.connect(modifier.adjust_minimum_range) + range_max_slider.valueChanged.connect(modifier.adjust_maximum_range) - backgroundCheckBox.checkStateChanged.connect(modifier.setPlotAreaBackgroundVisible) + backgroundCheckBox.checkStateChanged.connect(modifier.setBackgroundVisible) gridCheckBox.checkStateChanged.connect(modifier.setGridVisible) smoothCheckBox.checkStateChanged.connect(modifier.setSmoothDots) - modifier.backgroundEnabledChanged.connect(backgroundCheckBox.setChecked) + modifier.backgroundVisibleChanged.connect(backgroundCheckBox.setChecked) modifier.gridVisibleChanged.connect(gridCheckBox.setChecked) itemStyleList.currentIndexChanged.connect(modifier.changeStyle) |