| Ticket UUID: | 3519111 | |||
| Title: | Problem with horizontal scroll of treeview | |||
| Type: | Bug | Version: | None | |
| Submitter: | stefanlei | Created on: | 2012-04-18 12:07:55 | |
| Subsystem: | 88. Themed Tk | Assigned To: | fvogel | |
| Priority: | 7 High | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2020-04-25 09:44:22 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2020-04-25 09:44:22 | |||
| Description: |
The horizontal scrollbar for a ttk::treeview does not work as expected (and as it does for a text widget). While initially the scrollbar appears fine and a corresponding fraction of the tree is displayed, this changes after the tree has been displayed once in its full width. Afterwards the scrollbar is and remains forever at 100%, no matter how small a tree width is chosen.
The scroll command specified with the –xscrollcommand option is then always called with additional arguments 0.0 and 1.0.
Problem occurs with Tcl/Tk 8.5.11 on Windows 7 and SuSE Linux.
The following piece of code demonstrates the problem (If you replace ttk::treeview by text everything looks great):
# purpose: test horizontal treeview scrolling
wm withdraw .
toplevel .ft -takefocus 0
wm geometry .ft =80x300+80+80
ttk::frame .ft.lf
pack .ft.lf -expand yes -fill both
ttk::scrollbar .ft.lf.hs -orient horiz -command ".ft.lf.tf xview"
ttk::scrollbar .ft.lf.vs -command ".ft.lf.tf yview"
ttk::treeview .ft.lf.tf -show tree -xscrollcommand "hscrollf .ft.lf" -yscrollcommand "vscrollf .ft.lf"
grid .ft.lf.tf -row 0 -column 0 -sticky nsew
grid .ft.lf.vs -row 0 -column 1 -sticky ns
grid .ft.lf.hs -row 1 -column 0 -sticky we
grid rowconfig .ft.lf 0 -weight 1
grid columnconfig .ft.lf 0 -weight 1
# populate tree
foreach node [list " Entry0 " " Entry111111111111 " " Entry22222222222222222222 " " Entry3333333333333333333333333 "] {
.ft.lf.tf insert {} end -text $node
}
# Vertical scrolling
proc vscrollf {mw first last} {
if {[expr {$first > 0.0}] || [expr {$last < 1.0}]} {
grid $mw.vs -row 0 -column 1 -sticky ns
$mw.vs set $first $last
} else {catch {after idle grid remove $mw.vs}}
}
# Horizontal scrolling
proc hscrollf {mw first last} {
puts "f=$first, l=$last"
if {[expr {$first > 0.0}] || [expr {$last < 1.0}]} {
grid $mw.hs -row 1 -column 0 -sticky we
$mw.hs set $first $last
} else {catch {after idle grid remove $mw.hs}}
}
| |||
| User Comments: |
fvogel added on 2020-04-25 09:44:22:
Merged in core-8-6-branch and trunk. fvogel added on 2020-04-16 21:15:43: Non-regression test added (entry-2.1.1, in ttk/entry.test) in the bugfix branch. fvogel added on 2020-04-15 06:25:51: I have found the fix, which consists in not removing the scrollCmd AND calling TtkScrollbarUpdateRequired so that later calls to TtkScrolled have an actual effect and call again this scrollCmd. Indeed the error in the -scrollcommand callback may have been removed in the meantime. This is [2222bd7667]. fvogel added on 2018-10-02 19:19:01: Hmmm, let's try the removal of the scrollcommand disabling on error... For some reason simply keeping the -xscrollcommand like this:
Index: generic/ttk/ttkScroll.c
==================================================================
--- generic/ttk/ttkScroll.c
+++ generic/ttk/ttkScroll.c
@@ -104,12 +104,12 @@
Tcl_Release(corePtr);
if (code != TCL_OK && !Tcl_InterpDeleted(interp)) {
/* Disable the -scrollcommand, add to stack trace:
*/
- ckfree(s->scrollCmd);
- s->scrollCmd = 0;
Tcl_AddErrorInfo(interp, /* @@@ "horizontal" / "vertical" */
"\n (scrolling command executed by ");
Tcl_AddErrorInfo(interp, Tk_PathName(h->corePtr->tkwin));
Tcl_AddErrorInfo(interp, ")");
does not work. Ttk does not "catch up" when the xscrollproc becomes defined, contrary to what core/legacy widgets do. The scrolling still does not work when proc hscrollf/vscrollf become defined. jenglish added on 2018-10-01 17:57:00: > Can you explain the reason for this deletion of the scroll command? Checked my old source archives; this has been present from the very beginning (logic first appeared in the TEntry widget introduced 2004-06-14). Core widgets don't disable -[xy]scrollcommand on errors, I don't remember why Tile was implemented this way. > Would there be undesirable consequences if we simply removed the deletion of the command when it triggers an error? Since this behavior only affects programs with errors, it should be safe to remove. fvogel added on 2018-09-29 18:50:42: So this behaviour is intentional it seems. Can you explain the reason for this deletion of the scroll command? Using, say, a text widget instead of a ttk::treeview does produce the error as well, but it does not erase the -xscrollcommand. Would there be undesirable consequences if we simply removed the deletion of the command when it triggers an error?
package require Tk
wm withdraw .
toplevel .ft -takefocus 0
wm geometry .ft =80x300+80+80
ttk::frame .ft.lf
pack .ft.lf -expand yes -fill both
ttk::scrollbar .ft.lf.hs -orient horiz -command ".ft.lf.tf xview"
ttk::scrollbar .ft.lf.vs -command ".ft.lf.tf yview"
text .ft.lf.tf -xscrollcommand "hscrollf .ft.lf" -yscrollcommand "vscrollf .ft.lf"
grid .ft.lf.tf -row 0 -column 0 -sticky nsew
.ft.lf.tf cget -xscrollcommand ; # still correctly returns hscrollf .ft.lf
# contrary to the case of a ttk::treeview
fvogel added on 2018-09-24 19:39:04: Okay, got it! If I copy/paste the test script in wish I see the described behavior. But I also see something nobody mentioned so far: There are two errors, invalid command name "hscrollf" and same error for vscrollf. This error is due to the proc vscrollf and hscrollf being defined *after* the treeview gridding. At this point, clicking on the arrows of the horizontal scrollbar does NOT trigger the -xscrollcommand command: there is NO "f=... l=..." output at all! I'm sure you tried the test script by sourcing it: in this case it works as you describe Joe, and there is no issue I can see (but this would need further testing from my side to be sure)! Also if I change the test script simply by defining the two scroll procs before the level 0 code, then copy/pasting the script produces the correct results you describe. So this problem looks like something happens because the treeview wants to run the h/vscroll procs before these are defined. This should not be a problem (even if an error is triggered). Instead it looks like something is messed up and when later the procs become defined Tk does not execute the -xscrollcommand anymore since the first time it was undefined. Further analysis shows that the two errors trigger exactly on grid .ft.lf.tf -row 0 -column 0 -sticky nsew Then, running .ft.lf.tf cget -xscrollcommand then returns {} instead of the expected hscrollf .ft.lf (The above was observed on Windows but I doubt it would be different on other platforms). jenglish added on 2018-09-24 18:17:36: Yes, I tested it (Tcl/Tk 8.5.7, system version on CentOS 6) and again with a fresh build from core-8-6-branch (Tcl/Tk 8.6.8). I am not seeing the behavior described. What values for f= and l= does the test program output? When the window is resized large enough to fit the treeview widget, you should see f=0.0 l=1.0; and you should always see 0.0 <= f <= l <= 1.0. fvogel added on 2018-09-23 18:54:17: Joe, sorry to ask but did you actually try the script provided by the OP? Because I definitely see the issue on both Linux Debian 8 and Windows Vista with the current core-8-6-branch, altough the behavior is a bit different on the two platforms. Here is what I'm seeing (herebelow I'm talking about the *horizontal* scrollbar only): Linux Debian 8:
Windows Vista
jenglish added on 2018-09-19 22:44:18: If you add: .ft.lf.tf column #0 -stretch 0 to the above script, then the horizontal scrollbar will disappear and reappear as the window is resized, and when present will scroll the treeview contents horizontally. I am not sure what else is expected here. anonymous added on 2018-09-19 19:18:27: The horizontal scrollbar of the above example widget is non-functional for me regardless of the -stretch setting of column #0 This reflects my experience in attempting to use ttk::treeview elsewhere. The horizontal scrollbar appears never to function. Also see: http://wiki.tcl.tk/20065 comment MHo 2008-04-09: The problem seems to have been around for a long time. It makes the ttk::treeview widget unusable except in trivial applications. It would be extremely useful if it worked as expected. Tk 8.6.8 - Kubuntu Linux 16.04 -- SEH jenglish added on 2014-03-07 14:47:37: This behaviour can be changed by configuring all columns to '-stretch 0'. With stretchable columns (the default), the ttk::treeview widget will resize columns so that the widget fits exactly within the available space, and will only scroll horizontally if there is not enough room. | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki