I have trouble with focus and a HList.
I wanted my HList to have clickable headers:
- The intention being that the user could click on a header to indicate that the list should be sorted by that column
- I don't think HList natively supports clickable headers
- So I thought I'd use the -itemtype=>"window" feature
The code snippet attached at the end is the simplest test-case I could come up with.
You might think "Why would anyone have a GUI like this" ... but this code is purely to demonstrate the problem.
With the script running, and with the window made nice'n'wide, to demonstrate the problem:
- Start with your mouse hovering over Button1 and then move the mouse left and then vertically down through the ABC header and down into the HList ... the HList focus highlight rectangle appears (there is no need to click a HList entry).
- Return to Button1 and then move the mouse left and then vertically down through the DEF label and down into the HList ... the HList focus highlight rectangle no longer appears
- Return to Button1 and then move the mouse left and then vertically down through the GHI button and down into the HList ... again, the HList focus highlight rectangle no longer appears.
Isn't it curious that the highlight rectangle doesn't appear when in the HList entries when the mouse transitions through the Label and button widgets?
You may well be asking, "why is this important" ... well because, in my full script (not in this example) I have a keyboard binding for the Escape-key to unselect all HList entries ... but this only works when the HList has the keyboard focus ... and the keyboard focus seems to be very dependent on the route the mouse took to get to the HList.
Questions:
- Can anyone else reproduce this?
- As a side issue, why is the label DEF not centred (centered)?
- Any ideas as to how to get the HList focus when traversing through widgets as headers?
- Is there a better way to get clickable headers?
Thank you very much for your time.
Andrew
#!/usr/bin/perl
use Tk;
use Tk::HList;
my $mw = MainWindow->new();
$b1 = $mw->Button(-text=>"Button1")->pack();
$b2 = $mw->Button(-text=>"Button2")->pack();
$hlist = $mw->HList( -selectmode => 'single', -columns=>3, -background
+=>"Wheat", -header=>1)->pack(-fill=>'both',-expand=>1);
$hlist -> focusFollowsMouse();
$hlist -> headerCreate(0, -text=>"ABC");
$label = $hlist->Label(-text=>"DEF", -pady=>1);
$hlist -> headerCreate(1, -itemtype=>"window", -window=>$label);
$button = $hlist->Button(-text=>"GHI");
$hlist -> headerCreate(2, -itemtype=>"window", -window=>$button);
for (1..9) { $hlist->add($_);
$hlist->itemCreate($_, 0, -text=>"$_"x5);
$hlist->itemCreate($_, 1, -text=>"$_"x10);
}
MainLoop;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.