在Windows 7中的gtk + 3.0中。在hbox中停止按鈕以垂直擴展
我正在創建一個按鈕並將它們打包到水平框中。我已將展開設置爲FALSE。現在該按鈕不是沿x方向擴展,而是垂直擴展。我不希望按鈕也垂直擴展。
int main(int argc, char* argv[]) {
gtk_init(&argc, &argv);
GtkWidget* window = NULL;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Layout using BOX");
//gtk_widget_set_size_request(window, 50, 300);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(window, "delete_event", G_CALLBACK(gtk_main_quit), NULL);
GtkWidget* button[5] = {NULL};
for(int i = 0; i < 5; ++i) {
std::stringstream buton_label;
buton_label << "Button ";
buton_label << (i + 1);
button[i] = gtk_button_new_with_label(buton_label.str().c_str());
gtk_widget_set_hexpand(button[i], FALSE);
g_signal_connect(button[i], "clicked", G_CALLBACK(button_clicked_cb), (gpointer)window);
}
GtkWidget *hbox = NULL;
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
//hbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
for(int i = 0; i < 5; ++i) {
gtk_box_pack_start(GTK_BOX(hbox), button[i], FALSE, TRUE, 10);
}
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
按鈕垂直擴展,甚至添加gtk_widget_set_hexpand(button [i],FALSE); – dearvivekkumar
'hexpand'是**水平**展開。對於垂直展開,請使用'vexpand'。 – liberforce
同樣的結果,仍然按鈕正在垂直擴展 – dearvivekkumar