gpt4 book ai didi

c - 如何控制 GtkWidget 中前导空格的数量?

转载 作者:行者123 更新时间:2023-12-02 22:27:10 31 4
gpt4 key购买 nike

如何在 GtkWidget 中设置前导空格?正如您在下面的图像中看到的那样,用户名/密码小部件在窗口开始时离水平线有点远

enter image description here

我的代码:

  GtkWidget *window;
GtkWidget *login_label;
GtkWidget *username_label, *password_label;
GtkWidget *username_entry, *password_entry;
GtkWidget *ok_button;
GtkWidget *hbox0, *hbox1, *hbox2, *hbox3;
GtkWidget *vbox;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "hello");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 300);

g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

login_label = gtk_label_new("Login");
username_label = gtk_label_new("Username: ");
password_label = gtk_label_new("Password: ");
username_entry = gtk_entry_new();
password_entry = gtk_entry_new();

gtk_entry_set_visibility(GTK_ENTRY(password_entry), FALSE);
ok_button = gtk_button_new_with_label("Enter");

g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(print_username), ok_button);

hbox0 = gtk_hbox_new(TRUE, 5);
hbox1 = gtk_hbox_new(TRUE, 5);
hbox2 = gtk_hbox_new(TRUE, 5);
hbox3 = gtk_hbox_new(TRUE, 5);

vbox = gtk_vbox_new(FALSE, 10);

gtk_box_pack_start(GTK_BOX(hbox0), login_label, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox1), username_label, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox1), username_entry, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox2), password_label, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox2), password_entry, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox3), ok_button, FALSE, FALSE, 5);

gtk_box_pack_start(GTK_BOX(vbox), hbox0, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox3, FALSE, FALSE, 5);

gtk_container_add(GTK_CONTAINER(window), vbox);

gtk_widget_show_all(window);
gtk_main();

最佳答案

这取决于您用来存放这些小部件的容器类型。

假设它是一个 GtkVBox对于最外层,对于行具有单个小部件或多个 GtkBoxes,您应该查看 <a href="http://developer.gnome.org/gtk3/stable/GtkBox.html#gtk-box-pack-start" rel="noreferrer noopener nofollow">gtk_box_pack_start()</a> 的参数,尤其是 fill旗帜。

更新:根据您的评论,也许您应该尝试使用 <a href="http://developer.gnome.org/gtk3/stable/GtkGrid.html" rel="noreferrer noopener nofollow">GtkGrid</a>而不是盒子,使用网格更容易让东西很好地排列。

关于c - 如何控制 GtkWidget 中前导空格的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12801278/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com