Can’t get ScrolledWindow.set_propagate_natural_height() to work

Hi,

I have the following simple code python3/Gtk3

from gi.repository import Gtk
from gi.repository import Gdk


a = '''asdsad
asdas
das
d
asd
as
da
sd
a
sd
ad
asd'''



class MyApp(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
        scrolled = Gtk.ScrolledWindow()
        scrolled.set_propagate_natural_height(True)
        scrolled.set_max_content_height(800)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.set_vexpand(True)
        scrolled.add(box)
        self.add(scrolled)

        for x in range(20):
            box.add(create_textview())



def create_textview():
    scrolled = Gtk.ScrolledWindow()
    scrolled.set_overlay_scrolling(False)
    scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,
                        Gtk.PolicyType.AUTOMATIC)

    scrolled.set_propagate_natural_height(True)
    scrolled.set_max_content_height(300)

    text = Gtk.TextView()
    text.set_vexpand(True)
    buf = text.get_buffer()
    buf.insert(buf.get_start_iter(), a)
    scrolled.add(text)
    return scrolled


win = MyApp()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

Everything works on the top ScrolledWindow which is the Child of the Window

My Issue is with the ScrolledWindows that have the TextViews as Child in create_textview()

It seems the TextView does not propagate its height, all the Scrolled Windows always have the minimum space possible.

What i need is a ScrolledWindow that expands until a certain size and then shows scrollbars.

I encountered this use case over and over again, and it always causes me headaches, i have it working in some places of my app, but can’t find out why it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.