Re: After resizing Widget with table, table contents not properly displayed
Oliver Kreuer <[email protected]>
| Newsgroups | gmane.comp.kde.devel.perl |
|---|---|
| Message-ID | <[email protected]> |
Hello Richard,
I appended two example scripts. The first shows the strange update
behaviour. In the second script I reimplemented method resizeEvent. So
the second one works.
I also tried the Qt::debug qw(virtual) statement but unfortunately the
output doesn't give me a clue.
Oliver
Richard Dale wrote:
> On Wednesday 07 July 2004 08:24, Oliver Kreuer wrote:
>
>>Hello,
>>
>>one of my widgets contains a table which shows one or two columns with 5
>>rows of content.
>>If I resize the widget when the table shows two columns the table
>>content is not properly shown after resizing. For example, strings of
>>column two suddenly show up in column one after I maximized the widget
>>using the maximize button of the window manager decoration.
>>
>>Programs written in C++ don't show this strange behaviour.
>>
>>I've found a work around. I reimplemented the resizeEvent handler as
>>follows:
>>
>>sub resizeEvent
>>{
>> if ($filled eq "true")
>> {
>> table->updateContents();
>> }
>>}
>>
>>If my table is filled with content call "updateContents" for every
>>resize event.
>>But I think that normally Qt should handle this itself.
>>Any suggestions?
>
> This sounds a strange error - can you post a complete program which reproduces
> the problem. PerlQt has various debugging modes you can turn on to see which
> virtual method callbacks are being called, so you could add this to the top
> of your program and see if that gives any clues:
>
> use Qt::debug qw( virtual )
>
> -- Richard
> _______________________________________________
> Kde-perl mailing list
> [email protected]
> https://mail.kde.org/mailman/listinfo/kde-perl
_______________________________________________
Kde-perl mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-perl
table_example.one
(text/plain, 19 B)
One Two Three Four
table_example.two
(text/plain, 32 B)
1_1 1_2 2_1 2_2 3_1 3_2 4_1 4_2
table_notUpdated.pl
(application/x-perl, 4.9 KB)
#!/usr/bin/perl -w
# Form implementation generated from reading ui file 'table_example.ui'
#
# Created: Mon Jul 5 09:38:35 2004
# by: The PerlQt User Interface Compiler (puic)
#
# WARNING! All changes made in this file will be lost!
use strict;
use utf8;
use Qt::debug qw (virtual);
package table_example;
use Qt;
use Qt::isa qw(Qt::Widget);
use Qt::slots
tableOneRow => [],
tableTwoRows => [];
use Qt::attributes qw(
frame6
One_Row
table
Two_Rows
);
our $filled = "false";
sub NEW
{
shift->SUPER::NEW(@_[0..2]);
if ( name() eq "unnamed" )
{
setName("table_example" );
}
my $table_exampleLayout = Qt::GridLayout(this, 1, 1, 11, 6, '$table_exampleLayout');
frame6 = Qt::Frame(this, "frame6");
frame6->setFrameShape( &Qt::Frame::StyledPanel() );
frame6->setFrameShadow( &Qt::Frame::Raised() );
my $frame6Layout = Qt::GridLayout(frame6, 1, 1, 11, 6, '$frame6Layout');
my $spacer = Qt::SpacerItem(190, 20, &Qt::SizePolicy::Expanding, &Qt::SizePolicy::Minimum);
$frame6Layout->addItem($spacer, 1, 3);
One_Row = Qt::PushButton(frame6, "One_Row");
$frame6Layout->addWidget(One_Row, 1, 1);
table = Qt::Table(frame6, "table");
table->setNumRows( int(0) );
table->setNumCols( int(0) );
table->setReadOnly( 1 );
table->setSelectionMode( &Qt::Table::NoSelection() );
table->setLeftMargin(0); # don't show left vertical header
$frame6Layout->addMultiCellWidget(table, 0, 0, 0, 3);
Two_Rows = Qt::PushButton(frame6, "Two_Rows");
$frame6Layout->addWidget(Two_Rows, 1, 2);
my $spacer_2 = Qt::SpacerItem(190, 20, &Qt::SizePolicy::Expanding, &Qt::SizePolicy::Minimum);
$frame6Layout->addItem($spacer_2, 1, 0);
$table_exampleLayout->addWidget(frame6, 0, 0);
languageChange();
my $resize = Qt::Size(586, 482);
$resize = $resize->expandedTo(minimumSizeHint());
resize( $resize );
clearWState( &Qt::WState_Polished );
Qt::Object::connect(One_Row, SIGNAL "clicked()", this, SLOT "tableOneRow()");
Qt::Object::connect(Two_Rows, SIGNAL "clicked()", this, SLOT "tableTwoRows()");
}
# Sets the strings of the subwidgets using the current
# language.
sub languageChange
{
setCaption(trUtf8("Table Test") );
One_Row->setText( trUtf8("One Row") );
Two_Rows->setText( trUtf8("Two Rows") );
}
sub tableOneRow
{
my @lines = ();
$filled = "true";
open (FILE,"table_example.one") or die;
while (defined (my $line = <FILE>))
{
chomp($line);
push (@lines,$line);
clearTable();
table->setNumCols(1);
table->horizontalHeader()->setStretchEnabled(1);
table->horizontalHeader()->setClickEnabled(0,-1);
table->horizontalHeader()->setLabel(0,"Eine Spalte",-1);
table->setNumRows(scalar(@lines));
table->setFocusPolicy( &Qt::Table::NoFocus() );
my $row = 0;
foreach my $element (@lines)
{
table->setItem($row,0,Qt::TableItem(table,&Qt::TableItem::Never," $element"));
$row++;
}
}
}
sub tableTwoRows
{
my @col1 = ();
my @col2 = ();
$filled = "true";
open (FILE,"table_example.two") or die;
while (defined (my $line = <FILE>))
{
chomp($line);
my @parts = split/\s+/,$line;
push (@col1,$parts[0]);
push (@col2,$parts[1]);
clearTable();
table->setNumCols(2);
table->horizontalHeader()->setStretchEnabled(1);
table->horizontalHeader()->setLabel(0,"Erste Spalte",-1);
table->horizontalHeader()->setLabel(1,"Zweite Spalte",-1);
table->horizontalHeader()->setClickEnabled(0,-1);
table->setNumRows(scalar(@col2) > scalar(@col1) ? scalar(@col1) : scalar(@col2));
table->setFocusPolicy( &Qt::Table::NoFocus() );
my $row = 0;
foreach my $element (@col1)
{
table->setItem($row,0,Qt::TableItem(table,&Qt::TableItem::Never," $element"));
$row++;
}
$row = 0;
foreach my $element (@col2)
{
table->setItem($row,1,Qt::TableItem(table,&Qt::TableItem::Never," $element"));
$row++;
}
}
}
sub clearTable
{
if (table->numRows() > 0)
{
if (table->numCols() > 1)
{
for (my $elem = 0; $elem < table->numRows() ;$elem++ )
{
table->takeItem(table->item($elem,0));
table->takeItem(table->item($elem,1));
}
}
else
{
for (my $elem = 0; $elem < table->numRows() ;$elem++ )
{
table->takeItem(table->item($elem,0));
}
}
}
}
1;
package main;
use Qt;
use table_example;
my $a = Qt::Application(\@ARGV);
my $w = table_example;
$a->setMainWidget($w);
$w->show;
exit $a->exec;
table_upd.pl
(application/x-perl, 4.9 KB)
#!/usr/bin/perl -w
# Form implementation generated from reading ui file 'table_example.ui'
#
# Created: Mon Jul 5 09:38:35 2004
# by: The PerlQt User Interface Compiler (puic)
#
# WARNING! All changes made in this file will be lost!
use strict;
use utf8;
package table_example;
use Qt;
use Qt::isa qw(Qt::Widget);
use Qt::slots
tableOneRow => [],
tableTwoRows => [];
use Qt::attributes qw(
frame6
One_Row
table
Two_Rows
);
our $filled = "false";
sub NEW
{
shift->SUPER::NEW(@_[0..2]);
if ( name() eq "unnamed" )
{
setName("table_example" );
}
my $table_exampleLayout = Qt::GridLayout(this, 1, 1, 11, 6, '$table_exampleLayout');
frame6 = Qt::Frame(this, "frame6");
frame6->setFrameShape( &Qt::Frame::StyledPanel() );
frame6->setFrameShadow( &Qt::Frame::Raised() );
my $frame6Layout = Qt::GridLayout(frame6, 1, 1, 11, 6, '$frame6Layout');
my $spacer = Qt::SpacerItem(190, 20, &Qt::SizePolicy::Expanding, &Qt::SizePolicy::Minimum);
$frame6Layout->addItem($spacer, 1, 3);
One_Row = Qt::PushButton(frame6, "One_Row");
$frame6Layout->addWidget(One_Row, 1, 1);
table = Qt::Table(frame6, "table");
table->setNumRows( int(0) );
table->setNumCols( int(0) );
table->setReadOnly( 1 );
table->setSelectionMode( &Qt::Table::NoSelection() );
table->setLeftMargin(0); # don't show left vertical header
$frame6Layout->addMultiCellWidget(table, 0, 0, 0, 3);
Two_Rows = Qt::PushButton(frame6, "Two_Rows");
$frame6Layout->addWidget(Two_Rows, 1, 2);
my $spacer_2 = Qt::SpacerItem(190, 20, &Qt::SizePolicy::Expanding, &Qt::SizePolicy::Minimum);
$frame6Layout->addItem($spacer_2, 1, 0);
$table_exampleLayout->addWidget(frame6, 0, 0);
languageChange();
my $resize = Qt::Size(586, 482);
$resize = $resize->expandedTo(minimumSizeHint());
resize( $resize );
clearWState( &Qt::WState_Polished );
Qt::Object::connect(One_Row, SIGNAL "clicked()", this, SLOT "tableOneRow()");
Qt::Object::connect(Two_Rows, SIGNAL "clicked()", this, SLOT "tableTwoRows()");
}
# Sets the strings of the subwidgets using the current
# language.
sub languageChange
{
setCaption(trUtf8("Table Test") );
One_Row->setText( trUtf8("One Row") );
Two_Rows->setText( trUtf8("Two Rows") );
}
sub tableOneRow
{
my @lines = ();
$filled = "true";
open (FILE,"table_example.one") or die;
while (defined (my $line = <FILE>))
{
chomp($line);
push (@lines,$line);
clearTable();
table->setNumCols(1);
table->horizontalHeader()->setStretchEnabled(1);
table->horizontalHeader()->setClickEnabled(0,-1);
table->horizontalHeader()->setLabel(0,"Eine Spalte",-1);
table->setNumRows(scalar(@lines));
table->setFocusPolicy( &Qt::Table::NoFocus() );
my $row = 0;
foreach my $element (@lines)
{
table->setItem($row,0,Qt::TableItem(table,&Qt::TableItem::Never," $element"));
$row++;
}
}
}
sub tableTwoRows
{
my @col1 = ();
my @col2 = ();
$filled = "true";
open (FILE,"table_example.two") or die;
while (defined (my $line = <FILE>))
{
chomp($line);
my @parts = split/\s+/,$line;
push (@col1,$parts[0]);
push (@col2,$parts[1]);
clearTable();
table->setNumCols(2);
table->horizontalHeader()->setStretchEnabled(1);
table->horizontalHeader()->setLabel(0,"Erste Spalte",-1);
table->horizontalHeader()->setLabel(1,"Zweite Spalte",-1);
table->horizontalHeader()->setClickEnabled(0,-1);
table->setNumRows(scalar(@col2) > scalar(@col1) ? scalar(@col1) : scalar(@col2));
table->setFocusPolicy( &Qt::Table::NoFocus() );
my $row = 0;
foreach my $element (@col1)
{
table->setItem($row,0,Qt::TableItem(table,&Qt::TableItem::Never," $element"));
$row++;
}
$row = 0;
foreach my $element (@col2)
{
table->setItem($row,1,Qt::TableItem(table,&Qt::TableItem::Never," $element"));
$row++;
}
}
}
sub clearTable
{
if (table->numRows() > 0)
{
if (table->numCols() > 1)
{
for (my $elem = 0; $elem < table->numRows() ;$elem++ )
{
table->takeItem(table->item($elem,0));
table->takeItem(table->item($elem,1));
}
}
else
{
for (my $elem = 0; $elem < table->numRows() ;$elem++ )
{
table->takeItem(table->item($elem,0));
}
}
}
}
sub resizeEvent
{
if ($filled eq "true")
{
table->updateContents();
}
}
1;
package main;
use Qt;
use table_example;
my $a = Qt::Application(\@ARGV);
my $w = table_example;
$a->setMainWidget($w);
$w->show;
exit $a->exec;