Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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;

In reply to TK/HList and focus by andyok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-05-16 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (64 votes). Check out past polls.

    Notices?