SBGit-2019 / Pyside-QCP

Pyside2 bindings for QCustomplot
Other
16 stars 1 forks source link

Unable to add infinite lines to plot #5

Closed cd-86 closed 2 years ago

cd-86 commented 2 years ago
from PySide2.QtCore import Qt
from PySide2.QtGui import QPen
from PySide2.QtWidgets import QApplication
from qcustomplot_pyside2 import QCustomPlot, QCP, QCPScatterStyle, QCPItemStraightLine

# from PyQt5.QtCore import Qt
# from PyQt5.QtGui import QPen
# from PyQt5.QtWidgets import QApplication
# from QCustomPlot2 import QCustomPlot, QCP, QCPScatterStyle, QCPItemStraightLine

app = QApplication([])
customPlot = QCustomPlot()
customPlot.resize(800, 600)
customPlot.setInteractions(QCP.iRangeDrag)
customPlot.addGraph()
data = [i for i in range(100)], [i for i in range(100)]
customPlot.graph(0).setData(*data)
customPlot.graph(0).setScatterStyle(QCPScatterStyle(QCPScatterStyle.ssCircle, 5))
customPlot.legend.setVisible(True)
customPlot.xAxis.setLabel("Time")
customPlot.yAxis.setLabel("Value")
infLine = QCPItemStraightLine(customPlot)
infLine.setPen(QPen(Qt.red))
##############################################################################################
# Unable to add infinite lines to plot
# AttributeError: 'QCustomPlot.QCPItemStraightLine' object has no attribute 'point1'
infLine.point1.setCoords(50, 0)
infLine.point2.setCoords(50, 1)
##############################################################################################
customPlot.rescaleAxes()
customPlot.show()
app.exec_()
cd-86 commented 2 years ago

The same problem exists with QCPItemLine

SBGit-2019 commented 2 years ago

Thank you again for the report. It is indeed a bug. It is because not all public fields are exposed to python. I hoped we would only need method access not field access. But since this is not true we need to expose the public fields also to python. I will look into this.

SBGit-2019 commented 2 years ago

Fixed in release 2.1.5

This works now:

infLine.point1.setCoords(50, 0)
infLine.point2.setCoords(50, 1)