GtkEntry placeholder in GTK2



Hello,

I know GTK 3.2+ has a nice gtk_entry_set_placeholder_text() method, but I'm
wondering if there is some clever method to do something similar with GTK2,
I've not found anything googling around, but placeholder texts are a so
common interface concept today that I doubt that someone has not yet
"emulated" it in gtk2...

If no one has already done it, I think this could work:

- initialize the widget with placeholder text
- set a user data on the widget telling the text is placeholder
- set the color of the foreground text for this text widget to gray
- add a focus in event and a on change event on the widget
- if focus in and user data == placeholder, erase the text, save it in
another user data, remove the custom style from the gtkentry
- if on changed and result text empty reload the placeholder text and
switch the style
- if on changed and previous text was empty clear the placeholder text and
switch the style

I wonder if this can work... I can also build a subclass string with this
behaviour since I need this in a few different places :(

-- 
*Bye,*
* Gabry*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]