Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to force antialiasing on "translation only" drawPixmap?
Forum Updated to NodeBB v4.3 + New Features

How to force antialiasing on "translation only" drawPixmap?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 185 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlexGuo1998
    wrote on last edited by
    #1

    Hi all, when I call painter.drawPixmap() to render a pixmap to another pixmap, it does not always render antialiased.

    Here's the code. I'm using PyQt5 with Python3, but it shouldn't matter.

    class MyWidget(QtWidgets.QWidget):
        def __init__(self, parent):
            super(MyWidget, self).__init__(parent)
    
        def paintEvent(self, event):
            # paint the source image
            pixmap_orig = QtGui.QPixmap(10, 10)
            pixmap_orig.fill(QtCore.Qt.transparent)
            painter = QtGui.QPainter(pixmap_orig)
            painter.drawRect(0, 0, 9, 9)
            painter.end()
    
            # testing
            painter = QtGui.QPainter(self)
            painter.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform)
            painter.drawPixmap(QtCore.QRectF(10, 10, 10, 10), pixmap_orig, QtCore.QRectF(0, 0, 10, 10))
            painter.drawPixmap(QtCore.QRectF(10.5, 30, 10, 10), pixmap_orig, QtCore.QRectF(0, 0, 10, 10))
            painter.drawPixmap(QtCore.QRectF(10, 50, 10, 11), pixmap_orig, QtCore.QRectF(0, 0, 10, 10))
            painter.drawPixmap(QtCore.QRectF(10.5, 70, 10, 11), pixmap_orig, QtCore.QRectF(0, 0, 10, 10))
            painter.end()
    

    Result: (8x enlarged for easy viewing)
    result picture

    The 2nd square is drawn at (10.5, 30), 0.5px right from the 1st square. But it actually appears at (11, 30) with no antialiased border.
    The 3rd square is stretched to 10 x 11 and its left/right border is very clear.
    The 4th square is also 0.5px off, left/right border is antialiased.

    My question is: why doesn't the 2nd square render antialiased? how to force it to render antialiased? (I'm sure this is what I want)

    BTW painter.paintEngine().type() is 10 (i.e. QPaintEngine::Raster)

    Thanks!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved