Closed char101 closed 1 year ago
Test code
import sys
import math
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QPen, QBrush, QColor
from PyQt6.QtWidgets import QApplication, QMainWindow
from QCustomPlot2 import *
app = QApplication(sys.argv)
window = QMainWindow()
window.resize(800, 600)
customPlot = QCustomPlot()
window.setCentralWidget(customPlot)
graph0 = customPlot.addGraph()
graph0.setPen(QPen(Qt.GlobalColor.blue))
graph0.setBrush(QBrush(QColor(0, 0, 255, 20)))
graph1 = customPlot.addGraph()
graph1.setPen(QPen(Qt.GlobalColor.red))
x, y0, y1 = [], [], []
for i in range (251):
x.append(i)
y0.append(math.exp(-i/150.0)*math.cos(i/10.0)) # exponentially decaying cosine
y1.append(math.exp(-i/150.0)) # exponential envelope
graph0.setData(x, y0)
graph1.setData(x, y1)
customPlot.rescaleAxes()
customPlot.setInteraction(QCP.Interaction.iRangeDrag)
customPlot.setInteraction(QCP.Interaction.iRangeZoom)
customPlot.setInteraction(QCP.Interaction.iSelectPlottables)
window.show()
sys.exit(app.exec())
I'm also working on Qt6 support now. I guess it will be merged soon. Maybe I'll use some code from your proposal as well. My idea is to support building QCustomPlot module with either Qt5 or Qt6 using the same code base.
This is not really an issue, but I want to share some notes on building with PyQt6:
aqt install-qt windows desktop 6.4.0 win64_msvc2019_64
)pip install -U sip PyQt-builder PyQt6
Modify
pyproject.toml
project.py
-CPU_COUNT = os.cpu_count() if 'cpu_count' in dir(os) else 1 # number of parallel compilations +CPU_COUNT = 1 # os.cpu_count() if 'cpu_count' in dir(os) else 1 # number of parallel compilations
class QCustomPlotProject(PyQtProject): @@ -22,7 +22,7 @@ class QCustomPlotProject(PyQtProject): def update(self, tool): """Allows SIP to find PyQt5 .sip files.""" super().update(tool)
self.sip_include_dirs.append(join(PyQt5.path[0], 'bindings'))
self.sip_include_dirs.append(join(PyQt6.path[0], 'bindings'))
def build(self): self.build_qcustomplot()
QCPDataContainerIterator(QCPDataContainer *container, typename QCPDataContainer::iterator itr) :
m_pContainer(container), m_Iter(itr) {}
// QCPDataContainerIterator(QCPDataContainer *container, typename QCPDataContainer::iterator itr) :
// m_pContainer(container), m_Iter(itr) {} QCPDataContainerIterator(QCPDataContainer *container, typename QCPDataContainer::const_iterator itr) :
m_pContainer(container), m_Iter(const_cast<typename QCPDataContainer::iterator>(itr)) {}
m_pContainer(container), m_Iter(itr) {}
T *next() noexcept
const T next() noexcept { // NULL if we're at the end or current item and advance iterator return (m_Iter == m_pContainer->end()) ? nullptr : &(m_Iter++); }
T *get() noexcept
const T get() noexcept { // NULL if we're at the end or current item return (m_Iter == m_pContainer->end()) ? nullptr : &(m_Iter); }
typename QCPDataContainer::iterator iterator() const noexcept
typename QCPDataContainer::const_iterator iterator() const noexcept
{
return m_Iter;
}
protected: QCPDataContainer *m_pContainer;
typename QCPDataContainer::iterator m_Iter;
typename QCPDataContainer::const_iterator m_Iter;
};
endif // __QCUSTOMPLOT_SIP_DATACONTAINER_H
DataType *get();
const DataType *get(); %Docstring(format="deindented", signature="appended") Returns iterator current data point or None if iterator is invalid %End @@ -115,7 +115,7 @@ public: sipRes = sipCpp; %End
DataType *next();
const DataType *next(); %MethodCode sipRes = sipCpp->next(); if (!sipRes) {
SIP_SSIZE_T
withPy_ssize_t
Wheel build (rename to .whl):
QCustomPlot2-2.1.1.1-cp311-none-win_amd64.zip