in reply to Tk::Hlist header callbacks
HList headers cannot receive events in a useful way and there are no HList-specific callbacks that will do what you are looking for.
What is possible is to embed a widget within each header (though to be excruciatingly accurate it actually floats above the header), and bind to the embedded widgets -- not the header. You might also take a look at Tk::ResizeButton, which can be found on CPAN.
The following example was culled from one of my posts from the c.l.p.tk archives from back in 2001. I'm certain that there are other related examples to be found there as well.:
use Tk; use Tk::HList; my $mw = new MainWindow; my $hl = $mw->Scrolled('HList', -scrollbars => 'os', -background => 'white', -columns => 4, -header => 1, -width => 40, -height => 5 )->pack; my $bgcolor = "bisque"; foreach my $column (0 .. 3) { ## Create the Clickable Header my $b = $hl->Button( -background => $bgcolor, -anchor => 'center', -text => "Header$column", -command => sub { print "You pressed Header $column\n"; } ); $hl->headerCreate( $column, -itemtype => 'window', -borderwidth => -2, -headerbackground => $bgcolor, -widget => $b ); } MainLoop;
Some more comments from the same post:
Note the borderwidth of -2 for the headerCreate method. This is something I found by trial and error. I did not want there to be a borderwidth on both the button AND the header that HList creates, but if you don't set this value, then you will get both.
Also note that you are almost guaranteed to have a small section of space left after the the last header. I know of at least one way to "sort of" get around this. You can add an extra column in the HList widget that you don't use. It looks as though there is an empty header (unclickable of course) which fills up the remaining space. This is a similar approach that I've seen in some Windows GUI's.
You might also try resizing columns if the detect that the widget has been resized (bind to configure event, and compare reqWith reqHeight, etc), then adjust column sizes to whatever is appropriate.
In the past, what I have done is to embed a Frame widget which had "handles" (another frame widget) that I could use to enlarge/shrink column widths. A user would drag the handle causing a floating frame above the HList to show where the new column should be, and when the mouse was released, the column would be resized.
There are plenty of things you can use HList for, but I would be caution you against using very large datasets. I started noticing slowness at 10K or more cells when updating sorts. For large data sets, I'd recommend Tk::TableMatrix. Similar techniques can be applied to it.
HTH,
Rob
|
|---|