Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?

by jmlynesjr (Friar)
on Apr 06, 2013 at 03:04 UTC ( #1027242=note: print w/ replies, xml ) Need Help??


in reply to Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?

Helen:

Yet another idea from Steve Cookson from the mailing list is to use a Virtual ListCtrl with the no header option and then use a one line panel to create his own custom header. See his comments below:

Hi Guys, JL> Good idea. I should have thought of it! I look forward to seeing y +our implementation. Well here is what I did: 0) use i_LC_Header; #Attached. NB, I have commented out "use i_lib" and "__set_format" lines (without + testing) because these were my personal formatting. You can reinsti +tute your own routines if you want. 1) First of all add "|wxLC_NO_HEADER" to your Wx::ListCtrl like this $self->{Ctl_Appointments_Lst} = Wx::ListCtrl->new($self, wxID_ANY, wxDefaultPosition, wxDefaultSi +ze, wxLC_REPORT|wxSUNKEN_BORDER|wxLC_SINGLE_SEL|wxLC_NO_HEADER); 2) Create a 1-line panel with a sizer for your heading (using the atta +ched module): # Panel & sizer $self->{Ctl_Appointments_Panel_Szr} = Wx::BoxSizer->new(wxHORIZONT +AL); # New Sizer my $loc_panel = i_LC_Header->new($self, wxID_ANY, wxDefaultPositio +n, [1440,-1], wxBORDER_NONE, $self->{Ctl_Appointments_Panel_Szr} ); 3) Create as many column headers as you want like this: # Patient name column header $self->{Ctl_Appointments_Patient_Name_Pnl} = $loc_panel->AppendCol +umnHeader($self, wxID_ANY, wxDefaultPosition, [280, -1] , 'Patient Na +me'); (you must keep any existing column heading code like this, otherwise t +he table columns will not get created and you'll get a blank table n- +lines long: $self->{Ctl_Appointments_Lst} ->InsertColumn(0, 'Patient Name'); + # You probably don't need the name string here. $self->{Ctl_Appointments_Lst} ->SetColumnWidth(0, 275); ) 4) Add the new panel to your sizer BEFORE the ListCtrl itself, like th +is: $self->{Ctl_Appointments_Master_Szr}->Add($loc_panel, 0,0, 0); + # New header line. $self->{Ctl_Appointments_Master_Szr}->Add($self->{Ctl_Appointments +_Appointments_Lst}, 1, wxEXPAND, 0); Good luck. Any comments or improvements welcome. Regards Steve Cookson
#!/usr/bin/perl -w use strict; package i_LC_Header; use Wx qw[:everything]; use base qw(Wx::Panel); use strict; use warnings; #use i_lib qw(:i_Mage_common); # List of subroutines and global vari +ables # begin i_LC_Header::new sub new { my( $self, $parent, $id, $pos, $size, $style, $sizer ) = @_; $parent = undef unless defined $parent; $id = wxID_ANY unless defined $id; $pos = wxDefaultPosition unless defined $pos; $size = wxDefaultSize unless defined $size; $style = wxBORDER_NONE unless defined $size; $sizer = "" unless defined $sizer; # Panel & sizer $self = $self->SUPER::new( $parent, $id, $pos, $size, $style, $siz +er); # New Panel #__set_format ($self); $self-> SetBackgroundColour(Wx::Colour->new(10,10,20)); $self->SetSizer($sizer); $self->{sizer} = $sizer; return $self; } # begin i_LC_Header::AppendColumnHeader sub AppendColumnHeader { my( $self, $parent, $id, $pos, $size, $name ) = @_; $parent = undef unless defined $parent; $id = wxID_ANY unless defined $id; $pos = wxDefaultPosition unless defined $pos; $size = wxDefaultSize unless defined $size; $name = "" unless defined $name; my $style = wxBORDER_NONE; # Item header my $loc_item_pnl = Wx::Panel->new( $self, $id, $pos, $size, $style +, "" ); my $loc_item_szr = Wx::BoxSizer->new(wxHORIZONTAL); $loc_item_pnl->SetSizer($loc_item_szr); $loc_item_pnl->SetMinSize($size); #__set_format ($loc_item_pnl); $loc_item_pnl-> SetBackgroundColour(Wx::Colour->new(10,10,20)); my $loc_item_lbl = Wx::StaticText->new($loc_item_pnl, wxID_ANY, $n +ame, wxDefaultPosition, wxDefaultSize, ); # __xy_size(300), ); $loc_item_lbl-> SetFont(Wx::Font->new(11, wxFONTFAMILY_SWISS, wxFO +NTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, )); $loc_item_szr->Add($loc_item_lbl,0,0,0); $self->{sizer}->Add($loc_item_pnl,0,0,0); return $loc_item_pnl; } # end of class i_LC_Header 1;

James

There's never enough time to do it right, but always enough time to do it over...


Comment on Re: Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027242]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-07-30 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls