Hi Lars,

There are a few things that you can try to see if you can get the combo box to 
format how you want it. The first is to create the combo with 
gtk_combo_box_new_with_model(). That way you can setup your cell renderer and 
be able to set properties of how the combo box is going to be rendered. To help 
with the placement of the combo box widget you can use the widget expand and 
align functions. If you put the combo box in a box container then you have a 
few more things you can use for getting the alignment correct.

Eric


//gcc -Wall combo_size1.c -o combo_size1 `pkg-config --cflags --libs gtk+-3.0`

#include<gtk/gtk.h>

int main(int argc, char *argv[])
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Combo Size");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 100);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkTreeIter iter;
    GtkListStore *store=gtk_list_store_new(1, G_TYPE_STRING);
    gtk_list_store_append(store, &iter);
    gtk_list_store_set(store, &iter, 0, "Arial 20", -1);
    gtk_list_store_append(store, &iter);
    gtk_list_store_set(store, &iter, 0, "Arial 20, an extra long line to clip", 
-1);

    GtkCellRenderer *renderer=gtk_cell_renderer_text_new();
    g_object_set(renderer, "height", 30, "width", 200, "font", "Arial 20", 
NULL);

    GtkWidget *combo=gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
    gtk_widget_set_hexpand(combo, FALSE);
    gtk_widget_set_vexpand(combo, FALSE);
    gtk_widget_set_halign(combo, GTK_ALIGN_END);
    gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), 
GTK_CELL_RENDERER(renderer), "text", 0, NULL);

    g_object_unref(G_OBJECT(store));

    GtkWidget *box=gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), box);
   
    gtk_widget_show_all(window);
    gtk_main();
    return 0;   
  }

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to