Reputation: 317
So I have a listbox:
var listbox = new Gtk.ListBox();
var l = new Watcher.ListItem.NewItem("title","subtitle", "etc");
listbox.insert(l, 0);
"l" is basically a Gtk.ListBoxRow with formated labels and stuff.
I added a button with label "New" which purpose is to add new items into the ListBox.
int i = 1;
back_new.clicked.connect( ()=>{
l = new Watcher.ListItem.NewItem("title2", "subtitle2", "etc2");
listbox.insert(l, i);
i++;
});
The problem is if I check with "listbox.get_row_at_index(2)" it shows that there is something in the listbox so something happens but the listbox in the gui is not updated.
Full code is here if needed: http://pastebin.com/u/Levike
Upvotes: 2
Views: 6497
Reputation: 71
listbox.show_all() fixes my issue too.
my code was:
fist remove all items from listbox:
for row in self.gruppi_rows:
self.listboxGrp.remove(row)
then put some other objects in listbox, as following, but no content was showed in the list box:
row = Gtk.ListBoxRow()
self.count+=1
cbutton=Gtk.CheckButton(name)
flag1=self.radiobuttonSelectAll.get_active()
flag2=self.radiobuttonSelectNone.get_active()
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
cbutton.set_active(flag1)
box.pack_start(cbutton, True, True, 0)
row.add(box)
self.listboxGrp.add(row)
adding following line at the end fixes the problem:
self.listboxGrp.show_all()
Upvotes: 0
Reputation: 1195
it works for me. Anyway, yeah use Gtk.TreeView with 5 columns. 4 of them using Gtk.CellRendererText and 1 of them use Gtk.CellRendererPixbuf. Create a ListStore model, and get it from there so you can change the contain of the list anytime and just refresh it by calling "set_model". And by the way, set Gtk.TreeView property "headers-visible" to False, and voila, you get a markup Gtk.ListBox
Upvotes: 0
Reputation: 1195
Personally i would assume a Gtk.ListBoxRow is like iter in Gtk.TreeModel even though it's a Gtk.Container. You can skip adding a widget into ListBoxRow (straight to ListBox), and it will automatically a ListBoxRow for you whether you like it or not. Maybe it's a bug (maybe...), maybe the devs should implement a model with Gtk.ListBox, but for now, just use Gtk.Container.add () everytime you want to append something inside Gtk.ListBox. In your code:
int i = 1;
back_new.clicked.connect( ()=>{
l = new Watcher.ListItem.NewItem("title2", "subtitle2", "etc2");
listbox.insert(l, i);
i++;
});
# change to listbox.add (the widget...not the listboxrow widget) and it will show
the thing about Gtk.ListBox, it is a container where you can filter and sort the children inside, also to "stuffed" complicated list's children easier (Gtk.TreeView only uses Gtk.CellRenderer ).
If you do not want that, i don't think you should use it, or not until next release.
Upvotes: 0
Reputation: 2715
In other languages using gtk, I would do a l.show() to make sure the item becomes visible. Perhaps the same here ?
Upvotes: 0