我正在寻找限制 GtkComboBox 弹出窗口高度的方法,当达到该高度时,控件将获得滚动条。我找不到这样做的方法。列表从窗口的顶部流向底部(尝试附加的代码)。我检查了 API,但找不到有用的方法。我是 GTK+ 的新手,我已经在谷歌上搜索了好几天。
#include <gtk/gtk.h>
int main(int argc, char** argv) {
GtkWidget* frame;//main frame
GtkWidget* combobox;
GtkWidget* listbox;
GtkWidget* okbutton;
GtkWidget* cancelbutton;
GtkWidget* hbox_buttons;
GtkWidget* vbox;
gtk_init(&argc, &argv);
//create widgets
frame = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*Combobox issues*/
GtkListStore* list_store;
list_store = NULL;
GtkTreeIter iter;
list_store=gtk_list_store_new(1,G_TYPE_STRING);
int i;
for(i=0; i<100; i++) {
gtk_list_store_append(list_store, &iter);
gtk_list_store_set(list_store, &iter,0,"Residental", -1);
}
combobox = gtk_combo_box_new_with_model((GtkTreeModel *)list_store);
g_object_unref(G_OBJECT(list_store));
GtkCellRenderer* cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), cell, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox), cell, "text", 0, NULL);
listbox = gtk_list_new();
okbutton = gtk_button_new_with_label("Ok");
cancelbutton = gtk_button_new_with_label("Cancel");
//create containers
hbox_buttons = gtk_hbox_new(FALSE, 5);
vbox = gtk_vbox_new(FALSE, 5);
//Pack things
gtk_container_add(GTK_CONTAINER(frame),vbox);
gtk_box_pack_start(GTK_BOX(vbox), combobox, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), listbox, TRUE, TRUE, 5);
//pack buttons
gtk_box_pack_start(GTK_BOX(hbox_buttons), okbutton, TRUE, TRUE, 5);
gtk_box_pack_start(GTK_BOX(hbox_buttons), cancelbutton, TRUE, TRUE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox_buttons, FALSE, TRUE, 5);
//gtk_box_pack_start(vbox, listbox, TRUE, TRUE, 5);
g_signal_connect_swapped(G_OBJECT(frame), "destroy",
G_CALLBACK(gtk_main_quit), G_OBJECT(frame));
gtk_widget_show_all(frame);
gtk_main();
return 0;
}