GtkOverlay hides GtkTextView
<p>I'm trying to develop an application using <code>Gtk</code>, and I have run into a problem using <code>GtkOverlay</code>. If I have a <code>GtkOverlay</code> with a <code>GtkTextView</code> that was added using the standard container <code>add</code> method, the text is hidden. However, all other widgets, say for example, buttons, appear just fine. Even more odd is the fact that this behavior is only present if at least one widget was adding using <code>add_overlay</code>.</p>

<p><a href="http://i.stack.imgur.com/SG7up.png" rel="nofollow"><img src="http://i.stack.imgur.com/SG7up.png" alt="enter image description here"></a></p>

<p><a href="http://i.stack.imgur.com/CjYgD.png" rel="nofollow"><img src="http://i.stack.imgur.com/CjYgD.png" alt="enter image description here"></a></p>

<pre><code>#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

USE_OVERLAY = False

win = Gtk.Window()
text_view = Gtk.TextView()
overlay = Gtk.Overlay()
top_button = Gtk.Button()
bottom_button = Gtk.Button()
top_container = Gtk.VBox()
bottom_container = Gtk.VBox()

overlay_str = "( USE_OVERLAY = " + str(USE_OVERLAY) + ")"
win.set_title(overlay_str)

top_button.set_label("I'm a button on top!")
bottom_button.set_label("I'm a button on bottom!")
text_view.get_buffer().set_text("This should be visible")

win.add(overlay)
overlay.add(bottom_container)
bottom_container.pack_start(bottom_button, False, False, 0)
bottom_container.pack_end(text_view, True, True, 0)
if USE_OVERLAY:
    overlay.add_overlay(top_container)
    top_container.pack_end(top_button, False, False, 0)

win.connect("delete-event", Gtk.main_quit)
overlay.show_all()

win.show_all()
Gtk.main()
</code></pre>

<p>I have reason to believe that this is not a python problem, as the actual application is written using <code>haskell-gi</code>, however I figured more people would be familiar with python.</p>

<p>I don't know on what system your a running this example but it is working fine for me. The only caveat is that the top button appears over the bottom button and the <code>TextView</code> widget so I have to manually resize the <code>Window</code> to see the text. You can see a screen cast of my situation in this video: <a href="https://youtu.be/xoAH4OuEM0E" rel="nofollow">https://youtu.be/xoAH4OuEM0E</a></p>

<p>Now depending on what you really want there may be few different answers. What I would suggest is putting the <code>TextView</code> inside a <a href="https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ScrolledWindow.html" rel="nofollow"><code>ScrolledWindow</code></a>. This way the TextView will be at least visible before you would need the resize the window. It would also have the consequence to provide scrollbars if the text overflow the visible area.</p>

<p>It could look like this:</p>

<pre><code>import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

USE_OVERLAY = True

win = Gtk.Window()
text_view = Gtk.TextView()
overlay = Gtk.Overlay()
top_button = Gtk.Button()
bottom_button = Gtk.Button()
top_container = Gtk.VBox()
bottom_container = Gtk.VBox()

overlay_str = "( USE_OVERLAY = " + str(USE_OVERLAY) + ")"
win.set_title(overlay_str)

top_button.set_label("I'm a button on top!")
bottom_button.set_label("I'm a button on bottom!")
text_view.get_buffer().set_text("This should be visible")

# This is where the text_view is inserted in a ScrolledWindow
scrolled_window = Gtk.ScrolledWindow()     
scrolled_window.add(text_view)

win.add(overlay)
overlay.add(bottom_container)
bottom_container.pack_start(bottom_button, False, False, 0)
# The scrolled_window is inserted in the bottom_container
bottom_container.pack_end(scrolled_window, True, True, 0) 
if USE_OVERLAY:
    overlay.add_overlay(top_container)
    top_container.pack_end(top_button, False, False, 0)

win.connect("delete-event", Gtk.main_quit)
overlay.show_all()

win.show_all()
Gtk.main()
</code></pre>

<p>You can also see the result on the aforementioned screencast. The only drawback is that the top button won't be able to overlay as much the bottom layer as in your script. But maybe it won't bother you.</p>

python user-interface haskell gtk