QListBoxPixmap reimplementation problems
DUPUIS Arnaud <[email protected]> Wed, 20 Sep 2006 12:34:49 +0200
| Newsgroups | gmane.comp.kde.devel.perl |
|---|---|
| Organization | Infinity Perl |
| Message-ID | <[email protected]> |
Greetings all,
I am working on a program wich use PerlQt 3.008 or 3.009 (without PerlKDE to
be backward compatible with 3.008 from CPAN). I'm also using pqt-designer as
RAD.
The application I'm coding have a configuration window (what a surprise...)
and I'm using a QListBox on the right (vertically) and a QStackWidget on the
left for main display. This is absolutly like the KDE configurations dialogs,
at least I want to make it look like it.
In order to do that I have subclassed QListBoxPixmap to give it the
possibility of being highlited on mouse over. I attach to this mail the code
of the subclassed item.
In the main code i'm creating an item like that (in the init() method):
img_prices = Qt::Pixmap("$ENV{HOME}/.association_manager/images/prices.png");
my $i = ListBoxPixItem( img_prices,"Tarifs globaux");
listBox->insertItem( $i );
Later in the code I hook with the onItem( QListBoxItem* ) and onViewPort()
signals like that :
sub listBox_onItem # SLOT: ( QListBoxItem * )
{
my $i = shift ;
print "---------- update item (current: ",$i->text(),") ----------\n";
print "---------- previous: ",$previous_lb_item->text()," ----------\n"
if(defined($previous_lb_item));
listBox->updateItem( $i );
listBox->updateItem( $previous_lb_item ) if(defined($previous_lb_item)
&& $i != $previous_lb_item);
$previous_lb_item = $i;
}
sub listBox_onViewport
{
listBox->updateItem( $previous_lb_item ) if(defined($previous_lb_item));
}
Now the problem: this work fine for the first item (when my mouse is over it,
a filled rectangle is drawn) but only for this one...
I don't know why, nothing happen for the others items.
I'm sure i made a stupid error but I can't find it, so if you could help i'll
be glad !!
Good day
Arnaud DUPUIS
_______________________________________________
Kde-perl mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-perl
ListBoxPixItem.pm
(application/x-perl-module, 728 B)
package ListBoxPixItem;
use warnings;
use strict;
use utf8 ;
use Qt;
use Qt::isa qw(Qt::ListBoxPixmap);
use Qt::slots
redrawItem => [];
sub NEW
{
shift->SUPER::NEW(@_);
this->{state}=0;
}
sub paint
{
my $painter = shift;
if(this->{state})
{
this->{state}=0;
}
else
{
this->{state}=1;
}
if(!this->isSelected())
{
if(this->{state})
{
my $r = this->listBox()->itemRect(this);
print "[",this->text(),"] rect x=",$r->x()," y=",$r->y()," width=",$r->width()," height=",$r->height(),"\n";
$painter->fillRect($r,Qt::Brush(Qt::Color(94,170,178)));
$painter->drawRect($r);
}
}
my $f = $painter->font();
$f->setBold(1);
$painter->setFont($f);
Qt::ListBoxPixmap::paint( $painter );
}
1;