Vladimir Matveev
Vladimir Matveev

Reputation: 127791

Disable TreeView column "minimum size" behavior

I have three TreeView widgets inside two nested Paned widgets:

In other words, there are two TreeViews on the left and one on the right, and all of them can be resized. Also, all TreeViews are inside ScrolledWindows with horizontal scrollbar policy set to "never".

Both TreeViews on the left have only one column with text. When I move the slider in the top-level paned components to make the left two TreeViews smaller, I would expect for them to be clipped on the right if the width is too small to fit the text in the columns. Instead, it looks as if the entire TreeView (both of them) slides to the left, outside the window boundaries. This is very counterintuitive, and, more importantly, hide the expanders which are the first things which get hidden.

resize behavior

As you can see on the picture above, when I drag the vertical slider to the left, the columns in both of the TreeViews on the left slides "outside" of the window; the left boundary of the picture is also the left boundary of the window.

This behavior apparently depends on the maximum size of the values inside the column, that is, it starts this "sliding" only after the longest value no longer fits into the viewport, so it looks as if the TreeView or the column inside it have some minimum size which other components cannot shrink. However, I've set all potentially relevant minimum sizes to 0 just in case (although it does not work with the default absent minimum size as well).

Instead of this behavior, I want the TreeView and its column to be resized, hiding a part of the value on the right if it is necessary. But it seems that I cannot find anything in Gtk documentaion nor in Glade UI which would help me.

I'm using Python and pygobject/Gtk3, and I also use Glade to build the UI interactively.

Upvotes: 1

Views: 372

Answers (1)

Alexander Dmitriev
Alexander Dmitriev

Reputation: 2525

It's (most likely) CellRendererText who forbids the column to shrink. Try setting it's ellipsize property to Pango.EllipsizeMode.END, like in this example:

from gi.repository import Gtk, GObject, GLib, Pango

list_store = Gtk.ListStore(str)

window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
paned = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)

tree = Gtk.TreeView.new()
tree.set_model(list_store)
rend = Gtk.CellRendererText()
rend.set_property("ellipsize", Pango.EllipsizeMode.END)
column = Gtk.TreeViewColumn("title", rend, text=0)
column.set_resizable(True)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
tree.append_column(column)

for i in range (11):
    list_store.append(['ddt ' * 50])

paned.add1(tree)
paned.add2(Gtk.Label.new("hello"))
window.add(paned)

window.connect("destroy", Gtk.main_quit)
window.show_all()
Gtk.main()

Upvotes: 2

Related Questions