painter.drawline() , overlapping opacity problems with 100% opaque pen.
-
Not sure what optimisation flags you are setting on the graphics view but one possibility might be...
QGraphicsView::DontAdjustForAntialiasingor render hints set on the graphics view like...
QPainter::HighQualityAntialiasingand 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 :-)
-
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.
-
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. -
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? -
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).
-
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
This is not antialiasing related. Somehow lines get some opacity.
-
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()
-
Hello @Goffer. I made a test app with a QGraphicsView using the same settings as you here are the results so far.
Note: i did not bother to sub class a graphics item yet as I don't think it makes a difference.
I don't see those artifacts at 1:1 zoom scale.
zoom scale 1.0I do see those artifacts at less than a 1:1 zoom scale. I guess this is because the line thickness of on device pixel is now trying to show line a less than one physical device pixel width?? I think this is what the paint engine does when the device to logical pixels don't match, but I am no expert on that. You need to discuss those details with the developers.
zoom scale 0.5I used Qt 5.8.0
This is on macOS High Sierra 10.13
I will try it on Windows later and let you know the results.Hope that helps :-)