2
0
mirror of https://github.com/pyqt/examples.git synced 2025-08-29 12:57:41 +00:00

Merge pull request #14 from iyadahmed/patch-1

Fix and update mandelbrot example
This commit is contained in:
Michael Herrmann 2021-07-26 11:47:35 +02:00 committed by GitHub
commit 7069034401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -206,7 +206,7 @@ class RenderThread(QThread):
g = pow(g * s, 0.8) g = pow(g * s, 0.8)
b = pow(b * s, 0.8) b = pow(b * s, 0.8)
return qRgb(r*255, g*255, b*255) return qRgb(int(r*255), int(g*255), int(b*255))
class MandelbrotWidget(QWidget): class MandelbrotWidget(QWidget):
@ -251,7 +251,7 @@ class MandelbrotWidget(QWidget):
painter.save() painter.save()
painter.translate(newX, newY) painter.translate(newX, newY)
painter.scale(scaleFactor, scaleFactor) painter.scale(scaleFactor, scaleFactor)
exposed, _ = painter.matrix().inverted() exposed, _ = painter.transform().inverted()
exposed = exposed.mapRect(self.rect()).adjusted(-1, -1, 1, 1) exposed = exposed.mapRect(self.rect()).adjusted(-1, -1, 1, 1)
painter.drawPixmap(exposed, self.pixmap, exposed) painter.drawPixmap(exposed, self.pixmap, exposed)
painter.restore() painter.restore()
@ -263,10 +263,10 @@ class MandelbrotWidget(QWidget):
painter.setPen(Qt.NoPen) painter.setPen(Qt.NoPen)
painter.setBrush(QColor(0, 0, 0, 127)) painter.setBrush(QColor(0, 0, 0, 127))
painter.drawRect((self.width() - textWidth) / 2 - 5, 0, textWidth + 10, painter.drawRect((self.width() - textWidth) // 2 - 5, 0, textWidth + 10,
metrics.lineSpacing() + 5) metrics.lineSpacing() + 5)
painter.setPen(Qt.white) painter.setPen(Qt.white)
painter.drawText((self.width() - textWidth) / 2, painter.drawText((self.width() - textWidth) // 2,
metrics.leading() + metrics.ascent(), text) metrics.leading() + metrics.ascent(), text)
def resizeEvent(self, event): def resizeEvent(self, event):