[PyKDE] Trouble figuring out QCanvas and QCanvasView

David Boddie david at boddie.org.uk
Thu Oct 7 10:57:57 BST 2004


On Wed, 06 Oct 2004 11:47:03, Bryan O'Sullivan wrote: 
 
> On Wed, 2004-10-06 at 03:32 -0700, David Boddie wrote: 
> 
> > That's disappointing to hear. 
> 
> Think of it as an opportunity to write an article for one of the 
> developerworks, onlamp and so on sites :-) 
 
Well, good luck with that! ;-) 
 
> > I think that the problem is with the ownership of the QCanvas, although 
> > it's very strange if that really is the case since you pass it to the 
> > QCanvasView. I "fixed" your example so that it would work by giving the 
> > QCanvas a parent when it is created. I've included the modified code 
> > below. 
> 
> You're right!  It was just a one-line change that was required.  Well, 
> four bytes really.  Thanks.  I can safely say that this would not have 
> occurred to me. 
 
Generally, I find that in most cases where PyQt programs run, but don't 
work, the problems are caused by object ownership issues or just by 
objects "going out of scope". 
 
> Armed with this knowledge, I checked Troll Tech's Qt documentation, 
> along with the docs in theKompany's PyQtDoc product, and sure enough, 
> there's no mention anywhere of the fact that a QCanvas must have a 
> parent in order to actually render anything. 
 
I don't think that it actually needs one. Store the canvas object in 
the instance of your "Widge" class and the example will also work in 
the way you wanted. It seems that it isn't kept around for the 
QCanvasView to use despite being used by the QCanvasView. 
 
> By the way, everything also works if a QCanvasView, whose parent is a 
> QWidget, is the parent of the QCanvas. 
 
Yes, that would ensure that the QCanvas isn't deleted because the 
QCanvasView is referenced by the QVBoxLayout which is referenced by 
the widget, and so on. 
 
Maybe it's worth rewriting the example in C++ just to check whether the 
issue is purely to do with PyQt. 
 
David 


___________________________________________________________
$0 Web Hosting with up to 120MB web space, 1000 MB Transfer
10 Personalized POP and Web E-mail Accounts, and much more.
Signup at www.doteasy.com




More information about the PyQt mailing list