0
我正在畫一條線,但是如何保持線條'jag'免費且乾淨?如何平滑pyqt4上的曲線和對角線上的鋸齒狀邊緣?
這是上述繪製圖像的代碼。在這裏,我們可能會注意到圖像充滿了鋸齒狀的邊緣。
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.drawingPanel = DrawingPanel(self)
verticalLayout = QtGui.QVBoxLayout(self)
verticalLayout.addWidget(self.drawingPanel)
self.setLayout(verticalLayout)
self.resize(400, 300)
self.setWindowTitle('Review')
self.show()
class DrawingPanel(QtGui.QGraphicsView):
def __init__(self, parent):
super(DrawingPanel, self).__init__(parent)
scene = QtGui.QGraphicsScene()
self.setScene(scene)
pencil = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine)
self.scene().addLine(QtCore.QLineF(0, 0, 300, 600), pencil)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
這裏有圖片的縮放:
關於它的一些其他問題:
謝謝。也可以這樣做:'self.setRenderHint(QtGui.QPainter.Alliiasing); self.setRenderHint(QtGui.QPainter.TextAntialiasing); self.setRenderHint(QtGui.QPainter.SmoothPixmapTransform); self.setRenderHint(QtGui.QPainter.HighQualityAlliiasing);'? – user