Qt World Summit: Submit your Presentation

QPainter::drawRoundedRect not drawing regular rects?

  • It appears as though QPainter::drawRoundedRect is not drawing regular rectangles? I am using Qt-5.14.2.

    Both of the following two examples use this code:

            def paintEvent(self, e):
                p = QPainter(self)
                p.setPen(QPen(QColor('#5a9adb'), 1))
                rect = QRect(50, 50, 50, 50)
                p.drawRoundedRect(rect, 5, 5)

    The first example is on a display with devicePixelRatio == 1:
    Screen Shot 2020-04-04 at 11.05.30 AM.png

    The first example is on a display with devicePixelRatio == 2:

    Screen Shot 2020-04-04 at 11.11.51 AM.png

    You can see in the first example how the upper right and lower left corners are somewhat similar but irregular, but the upper left and lower right corners are unique.

    As a third example, here is how this plays out in some of my button types with devicePixelRatio == 2.

    Screen Shot 2020-04-04 at 11.18.26 AM.png

    ...using the following code:

            rect = self.rect()
            rect.setWidth(rect.width() - 1)
            rect.setHeight(rect.height() - 1)
            if self.isDown() or self.isChecked() and not self.checkedPixmap:
                p = QPainter(self)
                p.setRenderHint(QPainter.Antialiasing, True)
                p.setPen(QPen(QColor('#5a9adb'), 1))
                p.drawRoundedRect(rect, self.RADIUS, self.RADIUS)
                p = None

    What can I do to make rounded rectangles more regular? I would say that behavior is unacceptable.


Log in to reply