Search code examples
user-interfacegtkgtk3

How can I change the thickness of a GTKWidget?


This image shows a scene in my current app. This appearance is undesirable. The empty GtkList is only taking half the screen. How can I make it take four fifths of the screen and the done button take up one fifth? I am using the C programming language as always and Gtk3 which I just upgraded to. I am also having trouble with fat text entries, if there is a way to adjust the thickness of widgets. Making it homogeneous makes them all the same, but how can I make it NOT homogeneous but let me decide how much of the screen each widget gets?

#include "DisplayHelp.h"
#define NOTHING

void DisplayHelp(void) {
    gtk_main_quit(NOTHING);
    gtk_widget_destroy(Box);
    Box = gtk_vbox_new(0, 0);
    GtkWidget *Button = NULL;

    GtkWidget *List = gtk_list_box_new();
    gtk_container_add(GTK_CONTAINER(Box), List);
    gtk_container_add(GTK_CONTAINER(Window), Box);
    Button = gtk_button_new_with_label("Done");
    gtk_box_pack_start(GTK_BOX(Box), Button, 1, 1, FALSE);
    g_signal_connect(Button, "clicked", DisplayOptions, NULL);

    // I need a function to adjust the size of the button here

    printf("Entering the screen: Help\n");
    gtk_widget_show_all(Window);
    gtk_main();
}

Solution

  • You can use GtkGrid, set it's vertical homogenity to TRUE and set height for each widget with respect to desired proportions:

    grid = gtk_grid_new ();
    gtk_grid_set_row_homogeneous (grid, TRUE);
                                       /*l  t  w  h*/
    gtk_grid_attach (grid, top_widget,   0, 0, 1, 4);
    gtk_grid_attach (grid, bot_widget,   0, 0, 1, 1);
    

    However, it may be not the best design solution, as you are wasting space for button.