Re: PerlQT Canvas Sample?

Ashley Winters <[email protected]>
Newsgroups gmane.comp.kde.devel.perl
Message-ID <[email protected]>
--- Gerhard Stenzel <[email protected]> wrote:
> >Small? How about a one-liner?
> Thanks Ashley. Exactly what I was looking for. For the convenience 
> of other beginnners, I added some newlines to make it easier to read:
> 
> #!/usr/bin/perl
> use Qt;
> $a=Qt::Application(\@ARGV); 
> $c = Qt::Canvas 1000,1000; 
> $t = Qt::CanvasText "Howdy", $c; 
> show $t; 
> $cv = Qt::CanvasView $c;
> setMainWidget $a $cv; 
> show $cv; 
> $a->exec
> 
> This works, also for me. Now if I try to do the same thing in
> pqt-designer, it does not work ... I see a mainwindow, a canvasview
> with scrollbars, but no text.
> Obviously, I am making a rather trivial mistake, but fail to spot it.
> 
> I include the init() from pqt-designer:
> 
> sub init
> {
>     my $c = Qt::Canvas(1000,1000);
>     my $t = Qt::CanvasText("Howdy", $c);
>     $t->show();
>     my $cv = Qt::CanvasView($c, this);
>     $cv->setGeometry( Qt::Rect(10, 10, 200,200) );
>     $cv->show();
> }
> 
> Any ideas?

Yeah, you need to make the QCanvas a child object of `this' in order
for PerlQt to not delete it at the end of your init() function. PerlQt
will rescue my() variables from destruction at the end of a function
ONLY if they have a valid ->parent() object.

In that case, you need:

my $c = Qt::Canvas this;   # there's no QCanvas(QObject*,int,int)
$c->resize(1000,1000);     # so you have to resize() instead
...

Your other option is to store the canvas in an attribute instead of a
my() variable.

QCanvasItem objects are also subject to that parent requirement, but
PerlQt is smart enough to check ->canvas() instead of ->parent() on
them, so you shouldn't need to do anything else special for it to work.

Ashley Winters

> 
> Gerhard


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.