Delan Azabani
Delan Azabani

Reputation: 81394

GtkEntry text change signal

How can I connect a signal callback for any kind of change in a GtkEntry's buffer, including character added, deleted, text pasted or cut? I've looked in the docs for GtkWidget, GtkEntry and GtkEntryBuffer without finding this.

Note: if my question was badly worded, think of the HTML DOM's change event, except that it's fired greedily after every single keypress or event that causes a change, and not only checked on unfocus.

Upvotes: 11

Views: 11685

Answers (2)

Hocine Abderrahmane
Hocine Abderrahmane

Reputation: 21

g_signal_connect(GTK_EDITABLE(name of the entry), "changed", G_CALL_BACK( the function you want to call when the text in the entry changed), the argument);

exemple:

    GtkWidget* entry;
    
    void on_entry_changed(){
      printf("Function called\n");
    }
    
    int main(){
  // when the text in the entry changed it will call the function
      g_signal_connect(GTK_EDITABLE(entry), "changed", G_CALL_BACK(on_entry_changed), NULL);
    }

Upvotes: 0

detly
detly

Reputation: 30342

There is the changed signal (of the GtkEditable interface):

The ::changed signal is emitted at the end of a single user-visible operation on the contents of the GtkEditable.

E.g., a paste operation that replaces the contents of the selection will cause only one signal emission (even though it is implemented by first deleting the selection, then inserting the new content, and may cause multiple ::notify::text signals to be emitted).

(I found that by checking the implemented interfaces section.)

This indicates that you can also connect to the notify signal of the text property (specifically, notify::text).

There is also the preedit-changed signal:

If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.

Upvotes: 27

Related Questions