• Re: Horizontal scrolling of ttk::treeview

    From Alan Grunwald@[email protected] to comp.lang.tcl on Mon Jan 12 22:28:40 2026
    From Newsgroup: comp.lang.tcl

    On 10/01/2026 21:22, Brian wrote:
    Don't over think it. Pick a reasonable width based on the data. The user
    can resize the window to make it bigger. Use what you consider the
    minimum viewable size for -minwidth, which is where the scrollbar will
    take over. How much leading space you should account for depends on how
    much nesting you plan to do. Again, the user can resize the widget to
    see more.


    ...

    The immediate follow-up question that occurs to me is "What value
    should I choose for the -minwidth option?", which leads on to a couple
    of other questions:

    o     I can keep track of the various strings I want to display,
           determine their sizes using [font measure] and ensure that
           -minwidth and -width are set to their lengths, but what font
           should I specify? I could configure the font on a per-tag basis >>        and then find that font via [$tv tag configure {} -font] but that
           returns an empty string in my case, where I haven't configured a
           font. I guess it's TkDefaultFont - it would be nice not to have >>        to guess but I can't find anything in the documentation.

    o     How much leading space do I need to allow? In my example above,
           the strings are displayed on items that are down two levels. I >>        can find how much each level is indented via

           [ttk::configure [winfo style $tv] -indent]

           but if I add double the indent to the length of the longest
           string, and use the result to set -minwidth, it's not enough. I >>        guess the extra space is required by the icon used to indicate >>        that the some of the items have children, but I can't find what >>        that image is.

    Honestly? I think this stuff is hard and complicated enough that it
    ought to be done by the widget itself, and the fact that it doesn't
    should be regarded at least as a serious shortcoming, if not as a bug.

    Alan

    Sage advice.

    Sadly, I'm a good way down the track of trying to address this (and have already thought of an alternative way to fix things). This is important
    to me because I have treeview widgets with associated scrollbars in
    several places and I find that none of them scroll horizontally
    correctly and sometimes the user can't resize the treeview. This is
    probably because I'm not managing it correctly with grid/pack but I
    can't face tracking that down at the moment.

    In summary, this is a nice rat hole; I think I'll stay here for a while :-)


    Alan
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Brian@[email protected] to comp.lang.tcl on Mon Jan 12 18:22:03 2026
    From Newsgroup: comp.lang.tcl

    On 1/12/26 4:28 PM, Alan Grunwald wrote:
    On 10/01/2026 21:22, Brian wrote:
    Don't over think it. Pick a reasonable width based on the data. The
    user can resize the window to make it bigger. Use what you consider
    the minimum viewable size for -minwidth, which is where the scrollbar
    will take over. How much leading space you should account for depends
    on how much nesting you plan to do. Again, the user can resize the
    widget to see more.


    ...

    The immediate follow-up question that occurs to me is "What value
    should I choose for the -minwidth option?", which leads on to a
    couple of other questions:

    o     I can keep track of the various strings I want to display,
           determine their sizes using [font measure] and ensure that
           -minwidth and -width are set to their lengths, but what font >>>        should I specify? I could configure the font on a per-tag basis
           and then find that font via [$tv tag configure {} -font] but that
           returns an empty string in my case, where I haven't configured a
           font. I guess it's TkDefaultFont - it would be nice not to have
           to guess but I can't find anything in the documentation.

    o     How much leading space do I need to allow? In my example above, >>>        the strings are displayed on items that are down two levels. I >>>        can find how much each level is indented via

           [ttk::configure [winfo style $tv] -indent]

           but if I add double the indent to the length of the longest >>>        string, and use the result to set -minwidth, it's not enough. I
           guess the extra space is required by the icon used to indicate >>>        that the some of the items have children, but I can't find what
           that image is.

    Honestly? I think this stuff is hard and complicated enough that it
    ought to be done by the widget itself, and the fact that it doesn't
    should be regarded at least as a serious shortcoming, if not as a bug.

    Alan

    Sage advice.

    Sadly, I'm a good way down the track of trying to address this (and have already thought of an  alternative way to fix things). This is important
    to me because I have treeview widgets with associated scrollbars in
    several places and I find that none of them scroll horizontally
    correctly and sometimes the user can't resize the treeview. This is
    probably because I'm not managing it correctly with grid/pack but I
    can't face tracking that down at the moment.

    In summary, this is a nice rat hole; I think I'll stay here for a while :-)


    Alan

    Ok, then a few more suggestions. Use the heading field as a column
    title. In addition to showing the title, it also allows the user to
    manually resize the column by dragging the column divider, even if there
    is only 1 column. This will also update the scrollbar. So, the user can
    make it bigger without changing the window size.

    Check the Tk source library/demos directory for examples using treeview.
    It should also be included in most Tk installations.

    I'd also suggest sticking with just the grid geometry manager. Makes
    life a lot easier than using pack or mixing the two.

    --- Synchronet 3.21a-Linux NewsLink 1.2