[PyQt] Painting an arc... can't be that hard?
Scott Price
scottmprice at gmail.com
Fri Sep 5 19:47:31 BST 2008
So, using PyQt4/WindowsXP:
I'm attempting to adapt the basic drawing example for the simple purpose of
drawing an arc on the background of a widget. The following code opens a
main window with a child widget inside, but doesn't draw the arc. Probably
something simple that I'm missing, but I can't spot it... My eyes are
crossing from reading the documentation and attempting different things.
What have I missed?
import sys
from PyQt4 import QtGui, QtCore
class GroupDialog(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setBackgroundRole(QtGui.QPalette.Base)
self.drawMe()
def drawMe(self):
self.update()
def paintEvent(self, event):
rect = QtCore.QRect(10, 20, 80, 60)
self.pen = QtGui.QPen(QtCore.Qt.blue)
self.pen.setWidth(2)
self.pen.setCapStyle(QtCore.Qt.RoundCap)
self.pen.setStyle(QtCore.Qt.SolidLine)
startAngle = 30 * 16
arcLength = 120 * 16
painter = QtGui.QPainter()
painter.begin(self)
painter.setPen(self.pen)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.drawArc(rect, startAngle, arcLength)
painter.end()
class MyWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
groupDialog = GroupDialog()
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setWidget(groupDialog)
self.setCentralWidget(self.scrollArea)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mainwindow = MyWindow()
mainwindow.setGeometry(0,25,800,525)
mainwindow.show()
sys.exit(app.exec_())
Thanks!
Scott
More information about the PyQt
mailing list