• how to style one particular treeview

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Thu Jul 17 07:36:19 2025
    From Newsgroup: comp.lang.tcl

    I am using one particular ttk::treeview as a listbox:

    ttk::frame .ignoresForm.ignoresListFrame
    set ignoresList [ttk::treeview \
    .ignoresForm.ignoresListFrame.ignoresList -striped true \
    -yscrollcommand {.ignoresForm.ignoresListFrame.scrolly set}]
    ttk::style configure List.Treeview -indent 0
    #ttk::style map List.Treeview -indent [list disabled 0 active 0]
    $ignoresList configure -show tree -selectmode browse \
    -style List.Treeview
    $ignoresList column #0 -anchor w -stretch true
    ttk::scrollbar .ignoresForm.ignoresListFrame.scrolly -orient vertical \
    -command {.ignoresForm.ignoresListFrame.ignoresList yview}

    By default a ttk::treeview has an -indent of 20 pixels which makes sense
    for trees but is not needed for lists.

    In the code above I've tried to create a custom style to apply to one
    treeview but it has no effect whether I use ttk::style configure or
    ttk::style map.

    What is the correct way to do this?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Emiliano@emiliano@example.invalid to comp.lang.tcl on Thu Jul 17 12:36:45 2025
    From Newsgroup: comp.lang.tcl

    On Thu, 17 Jul 2025 07:36:19 -0000 (UTC)
    Mark Summerfield <m.n.summerfield@gmail.com> wrote:

    I am using one particular ttk::treeview as a listbox:

    ttk::frame .ignoresForm.ignoresListFrame
    set ignoresList [ttk::treeview \
    .ignoresForm.ignoresListFrame.ignoresList -striped true \
    -yscrollcommand {.ignoresForm.ignoresListFrame.scrolly set}]
    ttk::style configure List.Treeview -indent 0
    #ttk::style map List.Treeview -indent [list disabled 0 active 0]
    $ignoresList configure -show tree -selectmode browse \
    -style List.Treeview
    $ignoresList column #0 -anchor w -stretch true
    ttk::scrollbar .ignoresForm.ignoresListFrame.scrolly -orient vertical \
    -command {.ignoresForm.ignoresListFrame.ignoresList yview}

    By default a ttk::treeview has an -indent of 20 pixels which makes sense
    for trees but is not needed for lists.

    In the code above I've tried to create a custom style to apply to one treeview but it has no effect whether I use ttk::style configure or ttk::style map.

    What is the correct way to do this?

    Use

    ttk::style configure List.Treeview.Item -indicatorsize 0

    to suppress the space reserved for the open/close indicator. This might be ignored on Win/Mac with native themes.


    Regards
    --
    Emiliano
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Olivier@user1108@newsgrouper.org.invalid to comp.lang.tcl on Thu Jul 17 15:36:47 2025
    From Newsgroup: comp.lang.tcl


    Mark Summerfield <m.n.summerfield@gmail.com> posted:

    The trick is to use the headings, not the tree itself :

    set _names { ABC DEF GHI }

    ttk::treeview .mytree -columns ignored -show headings -yscrollcommand { .scrY set }

    .mytree heading ignored -text "Names"

    foreach _item $_names {

    .mytree insert {} end -values $_item

    }

    ttk::scrollbar .scrY -command { .mytree yview }

    pack .mytree -side left ; pack .scrY -side right -fill y

    Olivier.

    I am using one particular ttk::treeview as a listbox:

    ttk::frame .ignoresForm.ignoresListFrame
    set ignoresList [ttk::treeview \
    .ignoresForm.ignoresListFrame.ignoresList -striped true \
    -yscrollcommand {.ignoresForm.ignoresListFrame.scrolly set}]
    ttk::style configure List.Treeview -indent 0
    #ttk::style map List.Treeview -indent [list disabled 0 active 0]
    $ignoresList configure -show tree -selectmode browse \
    -style List.Treeview
    $ignoresList column #0 -anchor w -stretch true
    ttk::scrollbar .ignoresForm.ignoresListFrame.scrolly -orient vertical \
    -command {.ignoresForm.ignoresListFrame.ignoresList yview}

    By default a ttk::treeview has an -indent of 20 pixels which makes sense
    for trees but is not needed for lists.

    In the code above I've tried to create a custom style to apply to one treeview but it has no effect whether I use ttk::style configure or ttk::style map.

    What is the correct way to do this?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Thu Jul 17 16:08:58 2025
    From Newsgroup: comp.lang.tcl

    On Thu, 17 Jul 2025 12:36:45 -0300, Emiliano wrote:

    On Thu, 17 Jul 2025 07:36:19 -0000 (UTC)
    Mark Summerfield <m.n.summerfield@gmail.com> wrote:

    I am using one particular ttk::treeview as a listbox:

    ttk::frame .ignoresForm.ignoresListFrame
    set ignoresList [ttk::treeview \
    .ignoresForm.ignoresListFrame.ignoresList -striped true \
    -yscrollcommand {.ignoresForm.ignoresListFrame.scrolly set}]
    ttk::style configure List.Treeview -indent 0
    #ttk::style map List.Treeview -indent [list disabled 0 active 0]
    $ignoresList configure -show tree -selectmode browse \
    -style List.Treeview
    $ignoresList column #0 -anchor w -stretch true
    ttk::scrollbar .ignoresForm.ignoresListFrame.scrolly -orient vertical \ >> -command {.ignoresForm.ignoresListFrame.ignoresList yview}

    By default a ttk::treeview has an -indent of 20 pixels which makes sense
    for trees but is not needed for lists.

    In the code above I've tried to create a custom style to apply to one
    treeview but it has no effect whether I use ttk::style configure or
    ttk::style map.

    What is the correct way to do this?

    Use

    ttk::style configure List.Treeview.Item -indicatorsize 0

    to suppress the space reserved for the open/close indicator. This might be ignored on Win/Mac with native themes.


    Regards

    Thank you Emiliano, that worked great!

    I used:

    ttk::frame .ignoresForm.ignoresListFrame
    set ignoresList [ttk::treeview \
    .ignoresForm.ignoresListFrame.ignoresList -striped true \
    -yscrollcommand {.ignoresForm.ignoresListFrame.scrolly set}]
    ttk::style configure List.Treeview.Item -indicatorsize 0
    $ignoresList configure -show tree -selectmode browse \
    -style List.Treeview
    $ignoresList column #0 -anchor w -stretch true
    ttk::scrollbar .ignoresForm.ignoresListFrame.scrolly -orient vertical \
    -command {.ignoresForm.ignoresListFrame.ignoresList yview}

    --- Synchronet 3.21a-Linux NewsLink 1.2