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. painter.drawline() , overlapping opacity problems with 100% opaque pen.

painter.drawline() , overlapping opacity problems with 100% opaque pen.

Scheduled Pinned Locked Moved Unsolved General and Desktop
35 Posts 2 Posters 15.7k Views 2 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.
  • GofferG Offline
    GofferG Offline
    Goffer
    wrote on last edited by A Former User
    #1

    Hello guys

    I'm drawing 2 lines on top of each other, 1 long and 1 a bit shorter. I draw them on a QGraphicsItem.
    When I zoom out in my scene, I can see the ovelapping as if the longer line has some opacity, allowing me to see the shorter line below it. But if I zoom back, it looks all good.

    The color of my line is (180, 180, 180, 255) so no opacity.
    My line has a width of 1 pixel.

    My first guess is since 1px at no zoom is 1px, when I zoom out, my 1px becomes less than 1px (problem) but when I zoom in, it becomes more than 1px (so all good).

    Is there a solution to fix that ?

    Thx ! :)

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      Is it due to antialiasing effects perhaps?

      1 Reply Last reply
      0
      • GofferG Offline
        GofferG Offline
        Goffer
        wrote on last edited by
        #3

        from the view ?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kenchan
          wrote on last edited by
          #4

          Not sure what optimisation flags you are setting on the graphics view but one possibility might be...
          QGraphicsView::DontAdjustForAntialiasing

          or render hints set on the graphics view like...
          QPainter::HighQualityAntialiasing

          and I guess you read the docs here and here.

          Remember, all drawing uses the painter in the end unless you are using only OpenGL for your drawing.

          I hope this helps you find your way to a solution :-)

          1 Reply Last reply
          0
          • GofferG Offline
            GofferG Offline
            Goffer
            wrote on last edited by
            #5

            So I ve tried to turn off all the anitialiasing setting that I have + added the "DontAdjustForAntialiasing"

            self.setOptimizationFlag(QtWidgets.QGraphicsView.DontAdjustForAntialiasing)
            
            self.setRenderHint(QtGui.QPainter.Antialiasing, False)
            self.setRenderHint(QtGui.QPainter.TextAntialiasing, True)
            self.setRenderHint(QtGui.QPainter.HighQualityAntialiasing, False)
            self.setRenderHint(QtGui.QPainter.SmoothPixmapTransform, True)
            self.setRenderHint(QtGui.QPainter.NonCosmeticDefaultPen, True)
            self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
            

            I ve also tried

            self.setRenderHint(QtGui.QPainter.NonCosmeticDefaultPen, False)
            

            But I still have the same issue ... looks like it might not be aliasing related.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kenchan
              wrote on last edited by
              #6

              hmm... It might be helpful to see a screen shot of the results you are seeing.

              1 Reply Last reply
              0
              • GofferG Offline
                GofferG Offline
                Goffer
                wrote on last edited by
                #7

                0_1508028436519_bug2.jpg

                As you can see we see it on the small one but not on the zoomed in one.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kenchan
                  wrote on last edited by kenchan
                  #8

                  Yes, i can see what you mean about the smaller scale image. Just as a matter of interest, what does the smaller one look like when you zoom the pixels of your screen to the extent that you can see each pixel clearly?
                  As opposed to zooming it with the graphics view.

                  1 Reply Last reply
                  0
                  • GofferG Offline
                    GofferG Offline
                    Goffer
                    wrote on last edited by
                    #9

                    What do you mean ? When it's at scale 1:1 ?
                    The problem occurs as soon as on my screen it becomes less than 1 px

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kenchan
                      wrote on last edited by
                      #10

                      Sorry, I guessed you might not get what I meant.
                      What I meant was it would be nice to see an enlarged screen shot of your 1:1 display of it. i.e. can you apply a magnifying glass to the small image on your screen so one can see what the actual pixels look like?

                      1 Reply Last reply
                      0
                      • GofferG Offline
                        GofferG Offline
                        Goffer
                        wrote on last edited by
                        #11

                        0_1508029843148_Untitled-1.jpg

                        this one is 400%

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          kenchan
                          wrote on last edited by kenchan
                          #12

                          Thank you.
                          Well, I can see evidence of antialiasing on the line ends and the circles even though you have turned the antialiasing features off. I expect to see them on the text because you left the text antialiasing settings on. Horizontal lines look darker (more transparent?) and corners look lighter because they are drawn twice. Am I seeing this correctly?

                          So, either your antialias settings are getting changed at the last moment or your display device has a hardware antialiasing capability or it is actually getting that way due to windows scaling??

                          Other than that I am out of ideas. I use the graphics view in a similar fashion with the same settings as you and do not see that kind of thing. However, I do see exactly that kind of thing when I turn antialiasing on (the user can switch it on and off in my application).

                          1 Reply Last reply
                          0
                          • GofferG Offline
                            GofferG Offline
                            Goffer
                            wrote on last edited by Goffer
                            #13

                            My bad, this screenshot has the antialiasing on. Will do it again tomorrow with antialiasing off.

                            They can turn it too in mine but i feel like it shouldn't happen even with antialiasing on

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              kenchan
                              wrote on last edited by
                              #14

                              OK.
                              If you have issues with how the antialiasing is implemented I suggest you send your questions to the interest mailing list here and try to catch the eye of a developer who knows about the details.

                              1 Reply Last reply
                              0
                              • GofferG Offline
                                GofferG Offline
                                Goffer
                                wrote on last edited by
                                #15
                                self.setOptimizationFlag(QtWidgets.QGraphicsView.DontAdjustForAntialiasing)
                                
                                self.setRenderHint(QtGui.QPainter.Antialiasing, False)
                                self.setRenderHint(QtGui.QPainter.TextAntialiasing, False)
                                self.setRenderHint(QtGui.QPainter.HighQualityAntialiasing, False)
                                self.setRenderHint(QtGui.QPainter.SmoothPixmapTransform, True)
                                self.setRenderHint(QtGui.QPainter.NonCosmeticDefaultPen, False)
                                self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
                                

                                even with those settings, that's what I get

                                0_1508090592162_Untitled-1.jpg

                                This is not antialiasing related. Somehow lines get some opacity.

                                1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  kenchan
                                  wrote on last edited by
                                  #16

                                  Well that is strange isn't it.
                                  Maybe you could put the code that draws that into a minimal example app so we can all try to reproduce it.

                                  1 Reply Last reply
                                  0
                                  • GofferG Offline
                                    GofferG Offline
                                    Goffer
                                    wrote on last edited by
                                    #17

                                    Okay, I wrote a quick example with the same view settings.
                                    It looks fine at scale 1 and same problem when zooming out.

                                    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()
                                    
                                    1 Reply Last reply
                                    0
                                    • K Offline
                                      K Offline
                                      kenchan
                                      wrote on last edited by
                                      #18

                                      Great, i will give it a try when I can make a bit of time :-)

                                      1 Reply Last reply
                                      0
                                      • K Offline
                                        K Offline
                                        kenchan
                                        wrote on last edited by
                                        #19

                                        BTW, I don't use python so I will be testing it with C++. Someone else might pitch in and try it with python for you.

                                        1 Reply Last reply
                                        0
                                        • K Offline
                                          K Offline
                                          kenchan
                                          wrote on last edited by
                                          #20

                                          So which Version of Qt are you using for this? I assume you are using Windows right?

                                          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