I have drawn a chart by PyQtChart, and I want to move a series by mouse. Press right button to select a series, then move it to target location, after release right button put the series to target location.
I can get the selected series in update_select_series
, if I can get the original coordinates when I press right button and target coordinates, thus I can move the series to target location in update_series
, but I don't know how to implement it.
import sys
from PyQt5.QtChart import QAreaSeries, QChart, QChartView, QLineSeries, QValueAxis, QCategoryAxis
from PyQt5.QtCore import QPointF, Qt, QTimer
from PyQt5.QtGui import QColor, QGradient, QLinearGradient, QPainter, QPen
from PyQt5.QtWidgets import QApplication, QMainWindow
app = QApplication(sys.argv)
series0 = QLineSeries()
series0 << QPointF(1, 15) << QPointF(3, 17) << QPointF(7, 16) << QPointF(9, 17) \
<< QPointF(12, 16) << QPointF(16, 17) << QPointF(18, 15)
chart = QChart()
chart.addSeries(series0)
chart.createDefaultAxes()
chartView = QChartView(chart)
def update_select_series():
print('update_select_series')
def update_series():
print('update_series')
series0.pressed.connect(update_select_series)
series0.released.connect(update_series)
window = QMainWindow()
window.setCentralWidget(chartView)
window.resize(400, 300)
window.show()
sys.exit(app.exec_())