Attachment "ce470f20fd - treeview columns resize.tcl" to
ticket [caacf1f0]
added by
fvogel
2019-10-27 13:40:03.
# ce470f20fd - ttk::treeview allows dragging the right edge of the rightmost heading
# cc6c711c1e - treeview layout issues in 8.6.10 (regression)
# caacf1f082 - treeview column resizing not possible in some conditions
package require Tk
scrollbar .sh -orient horizontal -command {.tree xview}
ttk::treeview .tree -columns {bar colA colB colC foo} -padding 50 -xscrollcommand {.sh set}
.tree heading bar -text "-bar-"
.tree heading colA -text "-colA-"
.tree heading colB -text "-colB-"
.tree heading colC -text "-colC-"
.tree heading foo -text "Drag my right edge -->"
.tree insert "" end -values xxxxxxxxxxxxxxxxxxxxxxxxxx
pack .tree .sh -expand 1 -fill x
proc nostretch {} {
foreach col [.tree cget -columns] {
.tree column $col -stretch 0
}
.tree column #0 -stretch 0
}
proc allstretch {} {
foreach col [.tree cget -columns] {
.tree column $col -stretch 1
}
.tree column #0 -stretch 1
}
# 1. when no column is stretchable and one of them becomes stretchable
# the stretchable column takes the slack and the widget is redisplayed
# automatically
nostretch
.tree column colA -width 50 ; .tree column colB -width 50 ; # slack created
.tree column colA -stretch 1 ; # no slack anymore
# 2. only some columns are visible (and in a different order than declared in -columns)
# and a visible column becomes stretchable --> the stretchable column expands
nostretch
.tree configure -displaycolumns {colB colA colC}
.tree column colA -width 50 ; .tree column colB -width 50
.tree column colA -stretch 1
# 3. only some columns are visible (and in a different order than declared in -columns)
# and an invisible column becomes stretchable --> nothing happens
nostretch
.tree configure -displaycolumns {colB colA colC}
.tree column colA -width 50 ; .tree column colB -width 50
.tree column bar -stretch 1 ; # nothing changes since no stretchable column is displayed
.tree configure -displaycolumns {bar colB colA colC} ; # a stretchable colun became visible -> no slack
# 4. when the window width is less than needed for displaying the treeview entirely
# the columns are still resizable
allstretch
wm geometry . 700x340 ; # all columns stretched to be fully visible in reduced width
nostretch
wm geometry . 300x340 ; # some columns out of view, scrollbar makes them visible