Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unexpected type 'QSize' #79

Closed
luc-j-bourhis opened this issue Oct 3, 2023 · 4 comments
Closed

TypeError: unexpected type 'QSize' #79

luc-j-bourhis opened this issue Oct 3, 2023 · 4 comments

Comments

@luc-j-bourhis
Copy link

Code to trigger the bugs, with PyQt5 version 5.15.6 and PythonQwt version 0.10.2 (the latest release at the time of filling this bug)

import qwt
import numpy as np
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import Qt

trigger_bug = 1
#trigger_bug = 2

app = QtWidgets.QApplication([])

# Create plot widget
plot = qwt.QwtPlot("Trigonometric functions")
plot.insertLegend(qwt.QwtLegend(), plot.BottomLegend)

# Create two curves and attach them to plot
x = np.arange(10)
y = np.cos(x)
c = qwt.QwtPlotCurve.make(x, y, "Cosinus", plot)
c.setStyle(c.Sticks)
c.setPen(QtGui.QPen(Qt.red, 40))
archetype = qwt.QwtText("0")
archetype.setFont(QtGui.QFont())
txt_height = QtGui.QFontMetrics(archetype.font()).height()
for xi, yi in zip(x, y):
    match trigger_bug:
        case 1:
            s = qwt.QwtSymbol.make(style=qwt.QwtSymbol.NoSymbol,
                                   pen=QtGui.QPen(Qt.blue))
        case 2:
            s = qwt.QwtSymbol.make(style=qwt.QwtSymbol.Diamond,
                                   pen=QtGui.QPen(Qt.blue))
    m = qwt.QwtPlotMarker.make(xvalue=xi, yvalue=yi,
                               label=qwt.QwtText(f'{yi:.1f}'),
                               symbol=s)
    m.setLabelAlignment(Qt.AlignTop)
    m.setSpacing(2*txt_height)
    m.attach(plot)

# Resize and show plot
plot.resize(600, 300)
plot.show()

app.exec_()

With trigger_bug=1, I get this traceback:

File "...\qwt_trial.py", line 32, in <module>
  m = qwt.QwtPlotMarker.make(xvalue=xi, yvalue=yi,
File "...\site-packages\qwt\plot_marker.py", line 140, in make
  item.setSymbol(symbol)
File "...\site-packages\qwt\plot_marker.py", line 405, in setSymbol
  self.setLegendIconSize(symbol.boundingRect().size())
File "...\site-packages\qwt\symbol.py", line 1230, in boundingRect
  rect.setSize(self.__data.size)

builtins.TypeError: setSize(self, s: QSizeF): argument 1 has unexpected type 'QSize'

and with trigger_bug=2, I get this one:

File "...\qwt_trial.py", line 43, in <module>
  app.exec_()
File "...\site-packages\qwt\plot_canvas.py", line 586, in event
  return QFrame.event(self, event)
File "...\site-packages\qwt\plot_canvas.py", line 643, in paintEvent
  self.drawCanvas(painter, False)
File "...\site-packages\qwt\plot_canvas.py", line 707, in drawCanvas
  self.plot().drawCanvas(painter)
File "...\site-packages\qwt\plot.py", line 1418, in drawCanvas
  self.drawItems(painter, self.__data.canvas.contentsRect(), maps)
File "...\site-packages\qwt\plot.py", line 1442, in drawItems
  item.draw(painter, maps[item.xAxis()], maps[item.yAxis()], canvasRect)
File "...\site-packages\qwt\plot_marker.py", line 248, in draw
  self.drawLabel(painter, canvasRect, pos)
File "...\site-packages\qwt\plot_marker.py", line 319, in drawLabel
  symbolOff = self.__data.symbol.size() + QSizeF(1, 1)

builtins.TypeError: unsupported operand type(s) for +: 'QSize' and 'QSizeF'
@PierreRaybaut
Copy link
Collaborator

Thanks for the feedback and for the test code.
I'll look into it asap.

@PierreRaybaut PierreRaybaut changed the title More QSizeF bugs TypeError: unexpected type 'QSize' Oct 3, 2023
@luc-j-bourhis
Copy link
Author

Thanks for the fix! Any chance you make a new release? We have this package in my team's development environment, relying on Anaconda…

@PierreRaybaut
Copy link
Collaborator

Absolutely.
I was about to release a new version a few days ago.
I'll upload the V0.10.3 by tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants