I'm building a small podcast application for Linux using GTK-3.0 I want to use a listbox To hold Search results however when I add a widget to the listbox its far too small enter image description here
I've put all of the ui stuff into a header file.
#include<gtk/gtk.h>
#include <iostream>
extern "C"{
void createSearchResults(GtkWidget *e);
void MakeWindow(int *x,char ***y)
{
GtkWidget *listBox;
GtkWidget *window;
GtkBuilder *builder;
gtk_init(x,y);
builder = gtk_builder_new();
gtk_builder_add_from_file (builder, "PodcastWindow.glade", NULL);
listBox = GTK_WIDGET(gtk_builder_get_object(builder,"SearchListBox"));
window = GTK_WIDGET(gtk_builder_get_object(builder,"MainWindow"));
gtk_builder_connect_signals(builder,NULL);
g_object_unref(builder);
gtk_widget_show(window);
createSearchResults(listBox);
gtk_main();
return;
}
void on_MainWindow_destroy(){gtk_main_quit();}
void PodcastSearchEntry(GtkEntry *e){
itunesSearch(gtk_entry_get_text(e));
}
void createSearchResults(GtkWidget *e){
GtkWidget *tmp = gtk_label_new("helloWorld");
gtk_container_add(GTK_CONTAINER(e),tmp);
}
}
I think the issue is somewhere in this function
void createSearchResults(GtkWidget *e){
GtkWidget *tmp = gtk_label_new("helloWorld");
gtk_container_add(GTK_CONTAINER(e),tmp);
}
any help that can be offered would be greatly appreciated. PS if there are any formmating improvements I could make please let me know.
It's a bit hard to know what exactly is going wrong in your code without having a small example code that reproduces the issue.
That being said, one thing you should keep in mind, is that in GTK3, widgets are not visible by default (this got changed in GTK4 however). So what you probably want to do in your createSearchResults()
function is to add gtk_widget_show()
to the label you just made:
void createSearchResults(GtkWidget *e){
GtkWidget *tmp = gtk_label_new("helloWorld");
gtk_widget_show (tmp);
gtk_container_add(GTK_CONTAINER(e),tmp);
}
One possibility of analyzing where you have problems in your widget tree, is by taking a look with the GTK inspector. You can then click to inspect the widget that is not behaving as expected.