[PyKDE] Problems with QWMatrix and QCanvasView

Doug Bell doug101 at xecu.net
Fri Aug 24 01:42:42 BST 2001


Henrik Motakef wrote:
> Hi,
> 
> I want to create a QCanvasView which shows a "zoomed" version of it's Canvas. What I tried looked like this:
> 
> class ZoomedCanvasView(QCanvasView):
>     def __init__(self, canvas, parent):
>         QCanvasView.__init__(self, canvas, parent)
>         matrix = self.matrix = QWMatrix()
>         matrix.scale(2,2)
> 
>     def drawContents(self, painter, cx, cy, cw, ch):
>         painter.setWorldMatrix(self.matrix)
>         QCanvasView.drawContents(self, painter, cx, cy, cw, ch)
> 
> Unfortunately this doesn't work, in several ways: First, the last four parameters are not always passed, so an exception "Wrong number of arguments" is raised (This usually happens only in the first call of drawContents). However, when I change it to something like
> 
>    def drawContents(*args):
>        ...
>        apply(QCanvasView.drawContents, args)
> 
> another exception, "parameter 2 has wrong type", is raised - but not always. The third kind of error is not raising an exception at all, but simply not redrawing the CanvasItems properly after they scrolled out of the viewport an in again.
> 
> Is this a bug, or am I doing something terribly wrong?

This looks like the same problem that I've run into with QScrollView.
What is happening is that your drawContents overridden function is being called
for both QCanvasView.drawContents(self, painter, cx, cy, cw, ch) and
for QFrame.drawContents(self, painter).

The following has worked for me:

def drawContents(self, painter, clipX=None, clipY=None, \
                 clipW=None, clipH=None):
    if clipX == None:   # none is for wrong overridden function
        return QFrame.drawContents(self, painter)
    # rest of your draw code


Hope this helps,
Doug.




More information about the PyQt mailing list