[PyKDE] drawing on QCanvas not working
Peter Hinely
phinely at hawaii.edu
Sat May 5 04:59:13 BST 2001
Hello all,
I'm trying to accomplish the simple task of drawing an elipse on a QCanvas
viewed through a QCanvasView. I can draw the ellipse fine if I don't have
the QCanvasView inside a QMainWindow. But when I embed it in a
QMainWindow, the ellipse does not appear. Below is the code needed to
duplicated the problem. Can anything tell me whether I'm doing something
wrong or whether I've encountered a bug?
#!/usr/bin/env python
import sys, string
from qt import *
class TopologyCanvasView(QCanvasView):
def __init__(self, canvas, parent):
QCanvasView.__init__(self, canvas, parent)
class ApplicationWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self,None,'main window',Qt.WDestructiveClose)
self.file = QPopupMenu(self)
self.menuBar().insertItem('&File',self.file)
self.file.insertItem('E&xit',qApp,SLOT('closeAllWindows()'),Qt.CTRL +
Qt.Key_E)
newCanvas = QCanvas(200,200)
canvasView = QCanvasView(newCanvas, self)
self.setCentralWidget(canvasView)
item = QCanvasEllipse(20, 20, newCanvas)
item.setX(50)
item.setY(50)
item.setPen(QPen(Qt.red))
item.setBrush(QBrush(Qt.blue))
item.show()
canvasView.show()
self.statusBar().message('Ready',2000)
self.resize(350,400)
a = QApplication(sys.argv)
mw = ApplicationWindow()
mw.show()
a.connect(a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()'))
a.exec_loop()
#===========================================================
# This code without the QMainWindow works fine
# The code was written by someone on this list I think
#===========================================================
#!/usr/bin/env python
import sys
from qt import *
qapp=QApplication(sys.argv)
canvas=QCanvas(200, 400)
canvasView=QCanvasView(canvas)
item = QCanvasEllipse(20, 20, canvas)
item.setX(50)
item.setY(50)
item.setPen(QPen(Qt.red))
item.setBrush(QBrush(Qt.blue))
item.show()
canvas.resize(200, 200)
canvasView.show()
qapp.connect(qapp, SIGNAL('lastWindowClosed()'), qapp, SLOT('quit()'))
qapp.exec_loop()
More information about the PyQt
mailing list