Unsolved painter.drawline() , overlapping opacity problems with 100% opaque pen.
-
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.
-
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. -
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()
-
Great, i will give it a try when I can make a bit of time :-)
-
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.
-
So which Version of Qt are you using for this? I assume you are using Windows right?
-
I'm using Qt5 I think it's 5.6.1 and yes I'm on windows, will give it a try on MacOS
I've tried in Qt 4.8.2 and it's exactly the same -
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 :-)
-
Sorry but my images links are not showing up?? you will have to click on the links to see them I guess :-)
-
I've tried to make the pen cosmetic by setting the width to 0. That way the line should always have the same width on screen no matter the zoom factor. And the problem still occurs.
-
hello again @Goffer
I tried my test project on Windows and got the same results. It looks like we are stuck with that behaviour.
You could always submit it as a bug. -
I ve sent it to the interest mailing list as you suggested. Will see what happens, how could I submit it as a bug ?
-
-
I've submited the bug ticket.
-
what is the number of the bug report?
-
-
OK, got the link and voted for it.
-
lets see what happens ;)
-
@kenchan can you post your C++ example on the bug report ?
thx -
OK. I added my comments and zip file to the bug report.