1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#!/usr/bin/perl
use strict;
use warnings;
use QtCore4;
use QtGui4;
use StarDelegate;
use StarEditor;
use StarRating;
# [0]
sub populateTableWidget
{
my ($tableWidget) = @_;
my @staticData = (
{
title => 'Mass in B-Minor',
genre => 'Baroque',
artist => 'J.S. Bach',
rating => 5
},
{
title => 'Three More Foxes',
genre => 'Jazz',
artist => 'Maynard Ferguson',
rating => 4
},
{
title => 'Sex Bomb',
genre => 'Pop',
artist => 'Tom Jones',
rating => 3
},
{
title => 'Barbie Girl',
genre => 'Pop',
artist => 'Aqua',
rating => 5
},
);
foreach my $rowIndex ( 0..$#staticData ) {
my $row = $staticData[$rowIndex];
my $item0 = Qt::TableWidgetItem($row->{title});
my $item1 = Qt::TableWidgetItem($row->{genre});
my $item2 = Qt::TableWidgetItem($row->{artist});
my $item3 = Qt::TableWidgetItem();
$item3->setData(0,
Qt::qVariantFromValue(StarRating->new($row->{rating})));
$tableWidget->setItem($rowIndex, 0, $item0);
$tableWidget->setItem($rowIndex, 1, $item1);
$tableWidget->setItem($rowIndex, 2, $item2);
$tableWidget->setItem($rowIndex, 3, $item3);
}
}
# [4]
# [5]
sub main
{
my $app = Qt::Application(\@ARGV);
my $tableWidget = Qt::TableWidget(4, 4);
$tableWidget->setItemDelegate(StarDelegate($tableWidget));
$tableWidget->setEditTriggers(Qt::AbstractItemView::DoubleClicked()
| Qt::AbstractItemView::SelectedClicked());
$tableWidget->setSelectionBehavior(Qt::AbstractItemView::SelectRows());
my @headerLabels = qw( Title Genre Artist Rating );
$tableWidget->setHorizontalHeaderLabels(\@headerLabels);
populateTableWidget($tableWidget);
$tableWidget->resizeColumnsToContents();
$tableWidget->resize(500, 300);
$tableWidget->show();
return $app->exec();
}
# [5]
exit main();
|