Input method editor not showing when using gtk entry

I tried to create a simple barebone gtk app with only one entry in both gtk 3.24.20 on Ubuntu 20.04 and gtk 4.6.6 on Ubuntu 22.04. If you set the input system to ibus(the most commonly used) and IM to Chinese(Intelligent Pinyin), Chinese(WuBiHaifeng86), etc., the input method preedit never showed when you type and you always get en-US characters directly typed into the gtk entry.

Plus I also tried to implement Gtk.IMContext and Gtk.EventController(in gtk 4) with signals like commit and preedit-changed and methods like gtk_im_context_filter_key. Still failed to make it work. There are just too limited docs on this part. Not sure how I can bring up the IME that can select Chinese characters while I type with the correct implementation.

For people who speak Chinese: gtk 3.24.20 on Ubuntu 20.04 和 gtk 4.6.6 on Ubuntu 22.04 的GtkEntry无法使用ibus里的中文输入法,应该怎么才能让GtkEntry在输入的时候显示中文输入法呢?


Launch your GTK4 application with the environment variable GTK_DEBUG=interactive. The GTK inspector should show up. Go to the Global tab and check which value is set for Input Method.

Also, are you using libgtk binaries from the system, custom build or a Flatpak runtime?

Hi! Thanks for your reply! I am currently using the library directly from the ubuntu package manager installed by sudo apt-get install libgtk-4-dev.


Input Method

is always gtk-im-context-simple in my gtk4 testing app(on gtk 4.6.6 with x11 backend). Meanwhile, for my gtk3 testing app, the inspector does not show the info, but I assume that it should be the same.

This is the gtk4 code for the testing app

#include <gtk/gtk.h>

static void on_key_press(GtkEventControllerKey *controller, guint keyval, guint keycode, GdkModifierType state, gpointer data) {
    g_print("Key Press: %u\n", keyval);

static void on_key_release(GtkEventControllerKey *controller, guint keyval, guint keycode, GdkModifierType state, gpointer data) {
    g_print("Key Release: %u\n", keyval);

static void on_commit(GtkEditable *editable, const gchar *text, gpointer data) {
    g_print("Commit: %s\n", text);

static void on_preedit_changed(GtkIMContext *context, gpointer data) {
    gchar *preedit_string = NULL;
    gtk_im_context_get_preedit_string(context, &preedit_string, NULL, NULL);
    g_print("Preedit Changed: %s\n", preedit_string);

static void on_activate(GtkApplication *app, gpointer user_data) {
    GtkWidget *window = gtk_application_window_new(app);
    gtk_window_set_title(GTK_WINDOW(window), "GTK4 Entry Example");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);

    GtkWidget *entry = gtk_entry_new();
    gtk_window_set_child(GTK_WINDOW(window), entry);

    // GtkEventController *controller = gtk_event_controller_key_new();
    // g_signal_connect(controller, "key-pressed", G_CALLBACK(on_key_press), NULL);
    // g_signal_connect(controller, "key-released", G_CALLBACK(on_key_release), NULL);
    // gtk_widget_add_controller(entry, controller);

    // GtkIMContext *im_context = gtk_im_multicontext_new();
    // gtk_event_controller_key_set_im_context ((GtkEventControllerKey *)controller, im_context);

    // g_signal_connect(im_context, "commit", G_CALLBACK(on_commit), NULL);
    // g_signal_connect(im_context, "preedit-changed", G_CALLBACK(on_preedit_changed), NULL);


int main(int argc, char *argv[]) {
    GtkApplication *app = gtk_application_new("com.example.gtk4_entry_example", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL);
    int status = g_application_run(G_APPLICATION(app), argc, argv);

    return status;

Note: no matter whether the commented lines are added or not, the IME for Chinese is always not working. BUT Chinese input methods work correctly in my show applications search bar, terminal, browser, etc.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.