[PyKDE] Canvas problems
Boudewijn Rempt
bsarempt at rempt.xs4all.nl
Tue Dec 12 23:20:04 GMT 2000
On Tue, 12 Dec 2000, Mark Kimsal wrote:
>
> Eric doesn't seem to run on windows, some sort of permission problem when i hit
> the 'run' button. Could be that I just don't know how to work it though.
> Anyways, here is my code.
>
It's not the running that's important at the moment - if you load a Python
file, does Eric show it you? That's done with a canvas, too. When I run
your app on Linux I don't get any errors, but I don't see any output,
either.
What happens if you run the following absolutely minimal script:
import sys
from qt import *
qapp=QApplication(sys.argv)
canvas=QCanvas()
canvasView=QCanvasView(canvas)
item=QCanvasText('hello world',canvas)
item.setX(0)
item.setY(0)
item.show()
canvas.resize(100,100)
canvasView.show()
qapp.connect(qapp, SIGNAL('lastWindowClosed()'), qapp, SLOT('quit()'))
qapp.exec_loop()
Do you still get errors?
Your script didn't run - mainly because the stext item got garbage
collected/dereferenced as soon as the constructor was done, but also
because black text on a black background was a bit difficult to see.
The following shows hello world:
import sys
from qt import *
class ScrollView(QCanvasView):
def __init__(this,canvas,parent):
QCanvasView.__init__(this,canvas,parent,'viewport')
this.resize(parent.size())
this.setHScrollBarMode(QCanvasView.AlwaysOff)
this.setVScrollBarMode(QCanvasView.AlwaysOff)
class MainWindow(QWidget):
def __init__(self,parent = None,name = None,fl = 0):
QWidget.__init__(self,parent,name,fl)
if name == None:
self.setName('MainWindow')
self.resize(623,54)
grid = QGridLayout(self)
grid.setSpacing(0)
grid.setMargin(0)
self.canvas = QCanvas (self,'canvas')
#self.canvas.setBackgroundColor(Qt.black)
self.canvas.resize(self.size().width(),self.size().height())
viewport = ScrollView(self.canvas,self)
self.viewport = viewport
self.stext = QCanvasText('hello world',self.canvas)
#stext = QCanvasSprite(QCanvasPixmapArray("qt.png"),self.canvas)
self.stext.show()
grid.addWidget(self.viewport,0,0)
if __name__ == '__main__':
a = QApplication(sys.argv)
w = MainWindow()
a.setMainWidget(w)
w.show()
a.exec_loop()
More information about the PyQt
mailing list