Adding scrolledwindow to listbox/listboxrow causes background color to change to black

602 views Asked by At

I am using Ubuntu 14.10.

I am trying to create a GtkDialog for data entry. The dialog has a ListBox object with ListBoxRows containing mainly Gtk.Entry objects.

This all works fine until I add a ScrolledWindow with an embedded TextView object, which turns the background color of the surrounding areas (ListBox and ListBoxRows) to black:

Screenshot of window with black background

Here's a small sample to show the problem:

from gi.repository import Gtk

class MyDialog(Gtk.Dialog):
  def __init__(self,parent):
    Gtk.Dialog.__init__(self, "Sample", parent,
      Gtk.DialogFlags.MODAL, buttons=(
      Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
      Gtk.STOCK_OK, Gtk.ResponseType.OK
      ))    
    self.controls=[]

    mainbox=self.get_content_area()
    listbox = Gtk.ListBox()
    listbox.set_selection_mode(Gtk.SelectionMode.NONE)
    mainbox.pack_start(listbox, True, True, 0)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label1", xalign=0)
    self.controls.append(Gtk.Entry())
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(self.controls[0],True,True,0)
    listbox.add(row)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label2", xalign=0)
    self.controls.append(Gtk.Entry())
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(self.controls[1],True,True,0)
    listbox.add(row)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label3", xalign=0)
    scrollwindow = Gtk.ScrolledWindow()
    scrollwindow.set_hexpand(True)
    scrollwindow.set_vexpand(True)
    self.controls.append(Gtk.TextView())
    self.textbuffer = self.controls[2].get_buffer()
    self.textbuffer.set_text("Sample text")
    scrollwindow.add(self.controls[2])
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(scrollwindow,False,True,0)
    listbox.add(row)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label4", xalign=0)
    self.controls.append(Gtk.Entry())
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(self.controls[3],True,True,0)
    listbox.add(row)

    self.show_all()

class MyWindow(Gtk.Window):

  def __init__(self):
    Gtk.Window.__init__(self,title="Test")
    dialog= MyDialog(self)
    response = dialog.run()
    exit()


if __name__ == '__main__':
  win = MyWindow()
  Gtk.main()

To reproduce the problem, you have to enter a full line of text in the TextView area. With little/no text, it starts out normal, but as entering text, the background of the listbox changes to black.

Any ideas on what is causing this or how to work around it?

0

There are 0 answers