Reputation: 855
From a Gtk::Builder I've retried a pointer to a Gtk::ListBox from a glade file, called listbox_serverlist
.
Here is a minimal piece of code that I belive sums it up:
Gtk::ListBox* listbox_serverlist;
builder->get_widget("listbox_serverlist", listbox_serverlist);
Gtk::Label l;
l.set_text("Test");
listbox_serverlist->insert(l, -1)
Immediately after this, I run the main window, which the listbox is in.
My issue is that, although the listbox results in not being empty, there certainly isn't any text in it. I was hoping for my label to appear as an item in the list box, but instead there seems to be one selectable item, but it's completely blank.
Is there any code I must write to perhaps update the actual text in the label, or something to this effect?
I hope my question is clear, but I'd be happy to provide more information.
Upvotes: 2
Views: 763
Reputation: 1
For anyone else experiencing this issue, I recommend to add
Gtk::manage(WIDGET);
Example:
class MyListRow : public Gtk::ListBoxRow {
private:
Gtk::Label label;
Gtk::Box box;
public:
MyListRow(char const *appID) {
label.set_label(appID);
box.pack_start(label, Gtk::PACK_START, 0);
add(box);
show_all();
Gtk::manage(this);
}
};
In main:
listBox->append(*new MyListRow("title"));
Upvotes: 0
Reputation: 891
Since "it works for me":
#include <gtkmm.h>
int main()
{
auto Application = Gtk::Application::create();
Gtk::Window window;
Gtk::ListBox listbox;
window.add(listbox);
Gtk::Label label, label2;
label.set_text("asdf");
label2.set_text("qwer");
listbox.add(label);
listbox.insert(label2, -1);
window.show_all();
return Application->run(window);
}
my guess would be: are you using Gtk::Widget::show_all()? I have found that for some reason Gtk::Widget::show() was not enough for some hierarchies of widgets. Also I can't find it in 3.91 reference, so maybe that will change?
Upvotes: 2
Reputation: 3753
You have to insert a ListBoxRow and then add the Label to the Row.
Alternatively, the docs list gtk_container_add() as a solution.
Edit
I am not good at C++, but something like this should do the trick:
Gtk::ListBoxRow* list_box_row;
list_box_row.add(l); //add label widget to row
listbox_serverlist.add(list_box_row); //add row to listbox
Upvotes: 2