gpt4 book ai didi

c - 透明 float GtkEntry

转载 作者:行者123 更新时间:2023-11-30 16:02:56 25 4
gpt4 key购买 nike

我想开发一款可以接受多语言输入的游戏,包括中日韩字符。是否可以让 GtkDrawingArea 填充整个窗口并让 GtkEntry float 在其“顶部”?另外是否可以使 GtkEntry 的背景和边框透明?感谢您的帮助。

最佳答案

这是我在 my application 中的做法,具有一个函数,可以在父窗口部件顶部相对于父窗口部件左上角的坐标 (x,y) 处弹出一个包含一些文本的 GtkEntry:

GtkWidget *
popup_edit_window(GtkWidget *parent, gint x, gint y, const gchar *text)
{
gint px, py;
gdk_window_get_origin(gtk_widget_get_window(parent), &px, &py);

GtkWidget *edit_popup = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/* stackoverflow.com/questions/1925568/how-to-give-keyboard-focus-to-a-pop-up-gtk-window */
GTK_WIDGET_SET_FLAGS(edit_popup, GTK_CAN_FOCUS);
gtk_window_set_decorated(GTK_WINDOW(edit_popup), FALSE);
gtk_window_set_has_frame(GTK_WINDOW(edit_popup), FALSE);
gtk_window_set_type_hint(GTK_WINDOW(edit_popup), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
gtk_window_set_transient_for(GTK_WINDOW(edit_popup), GTK_WINDOW(parent));
gtk_window_set_gravity(GTK_WINDOW(edit_popup), GDK_GRAVITY_CENTER);

GtkWidget *entry = gtk_entry_new();
gtk_widget_add_events(entry, GDK_FOCUS_CHANGE_MASK);
gtk_entry_set_text(GTK_ENTRY(entry), text);

gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
gtk_container_add(GTK_CONTAINER(edit_popup), entry);
g_signal_connect_swapped(entry, "focus-out-event", G_CALLBACK(gtk_widget_destroy), edit_popup);
g_signal_connect(entry, "key-press-event", G_CALLBACK(on_edit_popup_key_press), edit_popup);

gtk_widget_show_all(edit_popup);
gtk_window_move(GTK_WINDOW(edit_popup), x + px, y + py);
/* GDK_GRAVITY_CENTER seems to have no effect? */
gtk_widget_grab_focus(entry);
gtk_window_present(GTK_WINDOW(edit_popup));

return edit_popup;
}

gboolean
on_edit_popup_key_press(GtkWidget *entry, GdkEventKey *event, GtkWidget *edit_popup)
{
switch(event->keyval) {
case GDK_Escape:
gtk_widget_destroy(edit_popup);
return TRUE;
case GDK_Return:
case GDK_KP_Enter:
/* here, do whatever you need to do when finished editing */
gtk_widget_destroy(edit_popup);
return TRUE;
}
return FALSE; /* event not handled */
}

为了使其透明,您应该能够执行以下操作:

gtk_window_set_opacity(GTK_WINDOW(edit_popup), 0.5);

但请注意,您的窗口管理器可能不支持它,或者可能选择忽略它。

但是,你有没有想过,GTK有相关的输入法库,用户可以选择任何自己想要的输入法来输入中日韩字符?无需重新发明轮子。

关于c - 透明 float GtkEntry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4631388/

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