Colouring text in a ComboBoxEntry

Hi,

I want to react to a user’s text entry by showing the text in red
when certain conditions are not met. All that I try results in the
text remaining black. Example nugget of code below, which doesn’t work
for me.

Is this even possible? What have I missed?

This is using Gtk 2.10.11, rubygnome 2-0.16.0-1, Ruby 1.8.5, Windows
XP.

Thanks, Martin.

================
Gtk.init

win = Gtk::Window.new
win.set_default_size( 640,480 )

blue_button = Gtk::Button.new(“blue”)
red_button = Gtk::Button.new(“red”)

combo = Gtk::ComboBoxEntry.new( true )
%w(hello world and beyond ).each{|t| combo.append_text( t ) }

blue_button.signal_connect(“clicked”){
combo.modify_text( Gtk::STATE_NORMAL, Gdk::Color.parse(‘blue’) )
}

red_button.signal_connect(“clicked”){
combo.modify_text( Gtk::STATE_NORMAL, Gdk::Color.parse(‘red’) )
}

hb = Gtk::HBox.new
hb.pack_start( blue_button )
hb.pack_start( red_button )
hb.pack_start( combo )

win.add( hb )

win.show_all

Gtk.main


This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

Martin P. wrote:

Hi,

I want to react to a user’s text entry by showing the text in red
when certain conditions are not met. All that I try results in the
text remaining black. Example nugget of code below, which doesn’t work
for me.

Is this even possible?

Absolutely, but it’s not immediately obvious what’s going on.
Fortunately this is one of those things where once it’s been pointed
out, it’s obvious.

Fact is, the Gtk::ComboBoxEntry doesn’t draw any text itself, it has a
child Gtk::Entry that handles the text entry and display. Therefore, to
set the colour of the text you have to modify the style of the
Gtk::Entry.

combo.child.modify_text( Gtk::STATE_NORMAL, Gdk::Color.parse(‘blue’) )

This is more obvious if you try it on a Gtk::Button. You can modify the
button text style till you’re blue in the face, but it’s the Gtk::Label
that is a child of the button that actually displays the text.

best,
Dan

Daniel L. wrote:

Fact is, the Gtk::ComboBoxEntry doesn’t draw any text itself, it has a
child Gtk::Entry that handles the text entry and display. Therefore, to
set the colour of the text you have to modify the style of the
Gtk::Entry.

combo.child.modify_text( Gtk::STATE_NORMAL, Gdk::Color.parse(‘blue’) )

super!
martin


This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/