GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Apr 18, 2014 11:18 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Changing the text color of a GtkEntry
PostPosted: Sat Feb 24, 2007 3:00 pm 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 2:52 pm
Posts: 13
The Gtk documentation says that gtk_widget_modify_text() is the function
to modify the text color of widgets such as GtkEntry. It also says that the
color given as parameter doesn't have to be allocated. However, when I try
this, the text color is not changed. I have no idea why it's not working:

Code:
#include <gtk/gtk.h>

int main(int argc, char* argv[])
{
    gtk_init(&argc, &argv);

    GtkWidget* mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(GTK_OBJECT(mainWindow), "destroy",
                     G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget* textField = gtk_entry_new();
    gtk_container_add(GTK_CONTAINER(mainWindow), textField);

    const GdkColor RED_COLOR = { 0, 65535, 0, 0 };
    gtk_widget_modify_text(textField, GTK_STATE_NORMAL, &RED_COLOR);

    gtk_widget_show_all(mainWindow);
    gtk_main();
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 3:15 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
This application changes the color to red on my computer... what version of GTK+ are you using? Also, maybe your theme is overriding the color?

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 3:39 pm 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 2:52 pm
Posts: 13
openldev wrote:
This application changes the color to red on my computer... what version of GTK+ are you using? Also, maybe your theme is overriding the color?


"pkg-config --modversion gtk+-2.0" answers "2.6.4".

Assuming the theme is overriding the color (which I don't think is the case, but who knows?) how can it be forced to change it anyways? I *need* red text.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 5:26 pm 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 2:52 pm
Posts: 13
It indeed seems that KDE is overriding the color setting. If I change the color of regular text in KDE, it changes to that in my application too. However, I really need to change the color of the text in the textfield to something else. Is there any reliable way to force that? It's really stupid if I can't give visual information to the user by coloring text when the window manager is messing with the colors. I need a realiable way of changing the color of the text to what I want.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 5:44 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
The problem is that there is no reliable way to do this on KDE that I know of. If you use a GNOME/GTK+ theme, this would not be the case. You could try using RC files to dictate the style, which may work, but I don't use KDE.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 7:26 pm 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 2:52 pm
Posts: 13
I can't believe the answer is "no, there's no reliable way of creating text fields with colored text using GTK". How can that be even possible? Hasn't anyone developing GTK or KDE ever thought that it should be possible to use colored text in text fields?

How about creating a kludge to do this? Is there any way of "simulating" a textfield in such way that KDE won't notice it's a text field and impose its own rules on it? In other words, if GtkEntry can't do it, then is there anything that can?

I really need that colored (editable) text.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group