in reply to Re: Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?
in thread Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?
James: I tried to translate and run your example. As you can see from the program here, it lets you set/change the font of a ListCtrl item, but not the headers (tried a couple of approaches).
(Unless I'm doing something wrong). (Although, interestingly, (as you can see by pressing the buttons), it does let you change the header text. But no font or color).
It's a pity, since, if your approach worked, I wouldn't need to start wrestling with Wx::Grid.
# Change header 2.pl: following James: http://www.perlmonks.org/?node_ +id=1025552 use strict; use warnings; use Wx; use 5.014; use autodie; use Carp; use Carp qw {cluck}; use Carp::Always; package MyFrame; use Wx ':everything'; use Wx ':listctrl'; use Wx::Event 'EVT_BUTTON'; use parent -norequire, 'Wx::Frame'; sub new { #1 MyFrame:: my ($class, $parent, $title) = @_; my $self = $class->SUPER::new( $parent, -1, # parent window; ID -1 means any $title, # title [150, 150 ], # position [ 350, 400 ], # size ); my $panel = Wx::Panel->new($self); my $itemCol = Wx::ListItem->new; $itemCol->SetText('Column 1'); my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'Arial'); $itemCol->SetFont($f); $self->{list_control} = Wx::ListCtrl->new($panel, -1, wxDefaultPosition, [ +320,100], wxLC_REPORT); # create a list control $self->{list_control}->InsertColumn(0, $itemCol); $self->{list_control}->SetColumnWidth(0, 100); $itemCol->SetText('Column 2'); $self->{list_control}->InsertColumn(1, $itemCol); $self->{list_control}->SetColumnWidth(1, 100); $itemCol->SetText('Column 3'); $self->{list_control}->InsertColumn(2, $itemCol); $self->{list_control}->SetColumnWidth(2, 100); $self->{list_control}->InsertStringItem( 0, 'Data 1' ); $self->{list_control}->SetItem( 0, 1, 'Data 3'); $self->{list_control}->InsertStringItem( 1, 'Data 2' ); $self->{list_control}->SetItem( 1, 1, 'Data 4'); my $btn_header = Wx::Button->new($panel, -1, 'Change header', +wxDefaultPosition, wxDefaultSize); my $btn_item = Wx::Button->new($panel, -1, 'Change item font', + wxDefaultPosition, wxDefaultSize); my $btn_header2 = Wx::Button->new($panel, -1, 'Change header2 +font', wxDefaultPosition, wxDefaultSize); EVT_BUTTON ($self, $btn_header, sub { $self->{list_control}->M +yFrame::on_header }); EVT_BUTTON ($self, $btn_item, sub { $self->{list_control}->MyF +rame::on_item }); EVT_BUTTON ($self, $btn_header2, sub { $self->{list_control}-> +MyFrame::on_item }); my $sizer = Wx::BoxSizer->new(wxVERTICAL); $sizer->Add($self->{list_control}, 0, wxALL, 10); $sizer->Add($btn_header, 0, wxALL, 10); $sizer->Add($btn_item, 0, wxALL, 10); $sizer->Add($btn_header2, 0, wxALL, 10); $panel->SetSizer($sizer); $panel->Layout(); return $self; } #1 end sub new MyFrame:: sub on_header { my $this = shift; say 'In on_header'; my $column = $this->GetColumn(1); say '$column->GetText =', $column->GetText; $column->SetMask(wxLIST_MASK_TEXT); $column->SetText('NEW TITLE'); my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'times new +roman'); $column->SetFont($f); $this->SetColumn(1, $column); } #1 end sub on_header sub on_item { my $this = shift; say 'In on_item'; my $item = $this->GetItem(1); my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'times new +roman'); say "In on_item, \$this= $this, \$item = $item, \$f= $f"; $item->SetFont($f); $this->SetItem($item); } #1 end sub on_item sub on_header2 { my $this = shift; say 'In on_header2'; my $itemCol = Wx::ListItem->new; $itemCol->SetText('Column 2'); my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'Arial'); $itemCol->SetFont($f); $this->SetColumn(1, $itemCol); } #1 end sub on_header2 # end package MyFrame:: package main; my $frame = MyFrame->new(undef, 'Setting headers'); $frame->Show(1); my $app = Wx::SimpleApp->new; $app->MainLoop; 1;
In the meantime, Anonymous Monk has provided another example based on your snippet - it's impressive to see DWIM in action.
Many thanks - Helen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?
by jmlynesjr (Deacon) on Mar 27, 2013 at 01:09 UTC | |
by HelenCr (Monk) on Mar 27, 2013 at 07:27 UTC | |
by jmlynesjr (Deacon) on Mar 27, 2013 at 15:26 UTC | |
by Anonymous Monk on Mar 27, 2013 at 07:49 UTC |