salsergey / QCustomPlot-PyQt

Bindings for graphics lib QCustomPlot for PyQt5 and PyQt6
MIT License
12 stars 1 forks source link

[Windows] PyQt6 build #3

Closed char101 closed 1 year ago

char101 commented 1 year ago

This is not really an issue, but I want to share some notes on building with PyQt6:

  1. Install Visual Studio 2019 buildtools (since Qt only provides vs2019 binaries)
  2. Install Qt 6.4 using the online installer or aqtinstall (aqt install-qt windows desktop 6.4.0 win64_msvc2019_64)
  3. Download jom.exe and put it somewhere on the path
  4. Install required modules: pip install -U sip PyQt-builder PyQt6
  5. Modify pyproject.toml

    diff --git a/pyproject.toml b/pyproject.toml
    index c50a287..853192e 100644
    --- a/pyproject.toml
    +++ b/pyproject.toml
    @@ -1,6 +1,6 @@
    # Specify the build system.
    [build-system]
    -requires = ['sip >=5.0.0, <7', 'PyQt-builder >=1.6, <2', 'PyQt5']
    +requires = ['sip >=5.0.0, <7', 'PyQt-builder >=1.6, <2', 'PyQt6']
    build-backend = 'sipbuild.api'
    
    # Specify the PEP 566 metadata for the project.
    @@ -35,11 +35,11 @@ classifier = [
     'Programming Language :: Python :: 3.11',
     'Topic :: Software Development :: User Interfaces'
    ]
    -requires-dist = 'PyQt5'
    +requires-dist = 'PyQt6'
    
    [tool.sip.project]
    sip-files-dir = 'sip'
    -abi-version = '12'
    +abi-version = '13.4'
    sdist-excludes = [
     '.*',
     '.*/*',
  6. Modify project.py
    
    diff --git a/project.py b/project.py
    index c7ba409..0698272 100644
    --- a/project.py
    +++ b/project.py
    @@ -6,10 +6,10 @@ import subprocess
    from os.path import join
    from sipbuild import Option
    from pyqtbuild import PyQtBindings, PyQtProject
    -import PyQt5
    +import PyQt6

-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)

Wheel build (rename to .whl):

QCustomPlot2-2.1.1.1-cp311-none-win_amd64.zip

char101 commented 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())

2022-11-28 16_56_45-python

salsergey commented 1 year ago

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.