C语言 GTK如何增加网格单元格的宽度和高度

jm81lzqq  于 2023-03-22  发布在  其他
关注(0)|答案(1)|浏览(119)

下面的代码使用下面的cat.jpg文件创建一个猫图标网格。

static void make_toggles(GtkWidget * window) {
    GtkWidget *stop_grid, vpaned;
    int i;
    stop_grid = gtk_grid_new();
    vpaned = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
    int num_stops = 10;
    char label[7]; label[0] = '\0';
    for (i = 0; i < num_stops; i++) {
        sprintf(label, "%d", i);
        stop = gtk_toggle_button_new_with_label(label);
        image = gtk_image_new_from_file("cat.jpg");
        gtk_button_set_child(GTK_BUTTON(stop), image);
        gtk_grid_attach(GTK_GRID (stop_grid), stop, i % 5 , 1 + (i/5), 1, 1); 
        g_signal_connect(stop, "toggled", G_CALLBACK(stop_toggle), NULL);
    }
    gtk_grid_set_column_spacing(GTK_GRID(stop_grid), 10);
    gtk_grid_set_row_spacing(GTK_GRID(stop_grid), 10);
    gtk_paned_set_start_child(GTK_PANED(vpaned), stop_grid);
    gtk_paned_set_resize_start_child(GTK_PANED(vpaned), TRUE);
    gtk_window_set_child (GTK_WINDOW (window), vpaned);
}

这是从应用程序激活处理程序调用的:

static void activate (GtkApplication* app, gpointer user_data) {
    GtkWidget *window;

    window = gtk_application_window_new (app);
    gtk_window_set_title (GTK_WINDOW (window), "Left Panel");
    gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
    make_toggles(window);
    gtk_widget_show (window);
}

然而,图标真的很小。有没有办法增加每个单元格的大小,这样猫就可以更清晰地看到?

kknvjkwl

kknvjkwl1#

虽然不是一个真正的答案,Gtk FlowBox更灵活一点,因为它的孩子自然地填充现有的空间。

相关问题