Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-63820

QPainter 1px 100% opaque overlapping lines become see through with distance.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.8.0
    • GUI: Painting
    • None
    • Windows 10 Qt 5.6.0 ~ 5.0.2

      MacOS 10.13 High Sierra xCode 9.0 on a Retina iMac
    • macOS

    Description

      Hello,

      I'm working on a nodal system in a QGraphicsView that I can zoom in/out.

      When I paint 1px lines (fully opaque) on my nodes, it's nicely displayed but if I start zooming out, The opacity level looks like it's changing since I can see through some lines and see lines below.

       

      Here is the link to the topic on the forum :

      https://forum.qt.io/topic/84154/painter-drawline-overlapping-opacity-problems-with-100-opaque-pen/26

       

      Here is some code to re-create the problem :

      
      from PySide2 import QtGui, QtCore, QtWidgets
      
      class TestView(QtWidgets.QGraphicsView):
      
          def __init__(self, parent=None):
              super(TestView, self).__init__(parent)
      
              self.setOptimizationFlag(QtWidgets.QGraphicsView.DontAdjustForAntialiasing)
              self.setRenderHint(QtGui.QPainter.Antialiasing, False)
              self.setRenderHint(QtGui.QPainter.HighQualityAntialiasing, False)
              self.setRenderHint(QtGui.QPainter.NonCosmeticDefaultPen, False)
              self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
              self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
              self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
              self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
      
          def wheelEvent(self, event):
              self.setTransformationAnchor(QtWidgets.QGraphicsView.AnchorUnderMouse)
      
              inFactor = 1.15
              outFactor = 1 / inFactor
      
              if event.delta() > 0:
                  zoomFactor = inFactor
              else:
                  zoomFactor = outFactor
      
              self.scale(zoomFactor, zoomFactor)
      
      class TestItem(QtWidgets.QGraphicsItem):
      
          def __init__(self):
              super(TestItem, self).__init__()
      
          def boundingRect(self):
              return QtCore.QRect(0, 0, 200, 400)
      
          def shape(self):
              path = QtGui.QPainterPath()
              path.addRect(self.boundingRect())
              return path
      
          def paint(self, painter, option, widget):
              brush = QtGui.QBrush(QtGui.QColor(70, 70, 70, 255))
              painter.setBrush(brush)
      
              painter.drawRoundedRect(0, 0, 200, 400, 20, 20)
      
              pen = QtGui.QPen(QtGui.QColor(200, 200, 200, 255))
              pen.setWidth(1)
              painter.setPen(pen)
      
              painter.drawLine(50, 50, 50, 300)
              painter.drawLine(50, 80, 50, 200)
              painter.drawLine(50, 80, 150, 80)
      
      
      view = TestView()
      scene = QtWidgets.QGraphicsScene()
      view.setScene(scene)
      
      item = TestItem()
      scene.addItem(item)
          
      view.show()
      
      

       

      thx

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.graphics.and.multimedia Qt Graphics Team
            goffer Loic Le Goff
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes