在Windows XP 32位版本上使用GTK 3.0并使用MinGW进行编译时,我遇到了一个相当奇怪的问题。 我已经开发了一个小的popup窗口,用三个文本条目填充networkingconfiguration(这里没有显示)。
在第一次出现时,第一个文本条目的值(10)是不可见的,并且必须通过在框上左击来显示:
左键单击后:
而且,通过反复按TAB,我可以隐藏每个文本条目! 但是,一旦条目被修改了,它就不会被隐藏了。
我尝试了很多东西( set_visibility
, set_overwrite
, "activation" signal
, "focus" signal
),但到目前为止,我还没有能够解决这个问题。
这里是源代码: Github Gist
和Makefile(更改您的计算机上的gtk src文件夹): Github Gist
#include <gtk/gtk.h> #include <glib/gstdio.h> /* * Network Configuration window being popped-up */ typedef struct network_conf_t { GtkWidget *window ; GtkWidget *vbox_frames ; GtkWidget *recv_frame ; GtkWidget *send_frame ; GtkWidget *recv_frame_hbox ; GtkWidget *recv_port_number_label; GtkWidget *recv_port_number_entry; GtkWidget *vbox ; GtkWidget *hbox ; GtkWidget *hbox2 ; GtkWidget * ip_address_label ; GtkWidget * port_number_label ; GtkWidget *ip_address_entry ; GtkWidget *port_number_entry ; } network_conf; unsigned int launch_netconf_popup() { network_conf netconf; /* Window configuration */ netconf.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_events ( netconf.window , GDK_FOCUS_CHANGE_MASK); gtk_window_set_resizable (GTK_WINDOW(netconf.window), FALSE); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(netconf.window), TRUE ); gtk_window_set_title (GTK_WINDOW(netconf.window), "Network Configuration" ); gtk_window_set_skip_pager_hint (GTK_WINDOW(netconf.window), TRUE ); g_signal_connect(G_OBJECT (netconf.window), "delete-event", G_CALLBACK(gtk_main_quit), NULL); gtk_window_set_position (GTK_WINDOW(netconf.window), GTK_WIN_POS_MOUSE); netconf.vbox_frames = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); netconf.recv_frame = gtk_frame_new( "Receive Options"); netconf.send_frame = gtk_frame_new( "Send Options" ); gtk_container_add (GTK_CONTAINER (netconf.window), netconf.vbox_frames); gtk_container_add (GTK_CONTAINER (netconf.vbox_frames), netconf.recv_frame); gtk_container_add (GTK_CONTAINER (netconf.vbox_frames), netconf.send_frame); /* Reception Port */ netconf.recv_frame_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20); netconf.recv_port_number_label = gtk_label_new ("Port :"); netconf.recv_port_number_entry = gtk_entry_new_with_buffer( gtk_entry_buffer_new("10", 8 ) ); //gtk_entry_set_alignment ( GTK_ENTRY(netconf.recv_port_number_entry), 0x1 ); gtk_container_add (GTK_CONTAINER (netconf.recv_frame), netconf.recv_frame_hbox); gtk_box_pack_start (GTK_BOX (netconf.recv_frame_hbox) , netconf.recv_port_number_label, FALSE, FALSE, 5); gtk_box_pack_end (GTK_BOX (netconf.recv_frame_hbox) , netconf.recv_port_number_entry, FALSE, FALSE, 5); /* Send Port and IP */ netconf.vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL , 2 ); netconf.hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 20); netconf.hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 20); netconf.ip_address_label = gtk_label_new("IP address :" ); netconf.port_number_label = gtk_label_new( "Port :" ); netconf.port_number_entry = gtk_entry_new_with_buffer( gtk_entry_buffer_new("0", 8 ) ); netconf.ip_address_entry = gtk_entry_new_with_buffer( gtk_entry_buffer_new("127.0.0.1", 16 )); //gtk_entry_set_alignment( GTK_ENTRY(netconf.ip_address_entry) , 0x1 ); //gtk_entry_set_alignment( GTK_ENTRY(netconf.port_number_entry), 0x1 ); gtk_container_add (GTK_CONTAINER (netconf.send_frame), netconf.vbox ); gtk_container_add (GTK_CONTAINER (netconf.vbox) , netconf.hbox ); gtk_container_add (GTK_CONTAINER (netconf.vbox) , netconf.hbox2); gtk_box_pack_start (GTK_BOX (netconf.hbox) , netconf.ip_address_label , FALSE, FALSE, 5); gtk_box_pack_start (GTK_BOX (netconf.hbox2), netconf.port_number_label, FALSE, FALSE, 5); gtk_box_pack_end (GTK_BOX (netconf.hbox) , netconf.ip_address_entry , FALSE, FALSE, 5); gtk_box_pack_end (GTK_BOX (netconf.hbox2), netconf.port_number_entry, FALSE, FALSE, 5); gtk_widget_show_all(netconf.window); return 0x00; } int main(int argc, char **argv) { gtk_init(0, NULL); launch_netconf_popup(); gtk_main(); return 0; }
这个:
gtk_entry_new_with_buffer(gtk_entry_buffer_new("10", 8))
是一个错误。
如果你检查gtk_entry_buffer_new()
的文档 ,你会看到第二个参数不是缓冲区内容的最大长度; 这是默认内容的长度,即第一个参数。 而"10"
显然不是 8个字符。 它应该是2
(或-1
使GTK +找出长度)。
我期望这会导致GTK +试图把字符串视为更长的时间,可能会触发一些未定义的行为(但我没有试试这个)一些混淆。