在Windows XP,32位版本上使用 GTK 3.0并使用 MinGW 进行编译时,我遇到了一个相当奇怪的问题。我已经为网络配置开发了一个小弹出窗口,其中包含三个文本条目,这些条目由conf结构填充(此处未显示)。
首次出现时,第一个文本条目的值(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;
}
答案 0 :(得分:1)
此:
gtk_entry_new_with_buffer(gtk_entry_buffer_new("10", 8))
是一个错误。
如果你check the documentation for gtk_entry_buffer_new()
,你会发现第二个参数不是缓冲区内容的最大长度;它是默认内容的长度,即第一个参数。显然,"10"
不 8个字符。它应该是2
(或-1
以使GTK +计算出长度。)
我认为当GTK +试图将你的字符串视为比它更长时,这会引起一些混乱,可能会触发一些未定义的行为(但我没有试过这个)。