← Back to list

[SOLVED] Why is the widget in this Listbox too small? GTK

Ted James · 2024-07-31 07:25 · 0 claps · 1.2 min read
#linux #gtk3 #linux-mint
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Why is the widget in this Listbox too small? GTK

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.

Solution

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.

Answered By — nielsdg

Answer Checked By — Gilberto Lyons (FixIt Admin)

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0


메타데이터
post_id
9ba32bf587cc
slug
solved-why-is-the-widget-in-this-listbox-too-small-gtk-9ba32bf587cc
url
https://medium.com/@fixitblog/solved-why-is-the-widget-in-this-listbox-too-small-gtk-9ba32bf587cc
canonical_url
https://medium.com/@fixitblog/solved-why-is-the-widget-in-this-listbox-too-small-gtk-9ba32bf587cc
author_url
https://medium.com/@fixitblog
status
ok
fetched_at
2026-07-23 06:21:08