Pyside2 error when using Qwidget.render() method, how to bypass?

Asked

Viewed 52 times

0

I am having trouble printing a widget. When executing the code below an error is returned.

    #p é uma instancia QPrinter

    painter = QPainter(p)
    painter.setRenderHint(QPainter.HighQualityAntialiasing)
    xscale = p.pageRect().width()/ self.width()
    yscale = p.pageRect().height()/ self.height()
    scale = min(xscale, yscale)
    painter.translate(p.paperRect().center())
    painter.scale(scale, scale)
    painter.translate((self.width()/2)*-1,(self.height()/2)*-1)
    self.render(painter)
    painter.end()

The error returned is:

Typeerror: 'Pyside2.QtWidgets.Qwidget.render' called with Wrong argument types: Pyside2.QtWidgets.Qwidget.render(Qpainter) PySide2.QtWidgets.QWidget.render(PySide2.QtGui.QPaintDevice, PySide2.QtCore.QPoint = Default(QPoint), PySide2.QtGui.QRegion = Default(QRegion), PySide2.QtWidgets.QWidget.RenderFlags = Instance(QWidget.RenderFlags(QWidget.DrawWindowBackground | QWidget.DrawChildren)))

What I don’t understand is, this same code in Pyqt5 works smoothly. Someone could help ?

Obs: I would not like to use pyqt5

1 answer

0


try to pass the parameters of the method surrender explicitly, try the following:

    painter = QPainter(p)
    painter.setRenderHint(QPainter.HighQualityAntialiasing)
    xscale = p.pageRect().width()/ self.width()
    yscale = p.pageRect().height()/ self.height()
    scale = min(xscale, yscale)
    painter.translate(p.paperRect().center())
    painter.scale(scale, scale)
    painter.translate((self.width()/2)*-1,(self.height()/2)*-1)
    self.render(painter,QPoint(0,0),painter.viewport()) #parametros expliclitos
    painter.end()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.