GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Changing the text color of a GtkEntry

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Warp
Familiar Face


Joined: 24 Feb 2007
Posts: 13

PostPosted: Sat Feb 24, 2007 3:00 pm    Post subject: Changing the text color of a GtkEntry Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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();
}
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Sat Feb 24, 2007 3:15 pm    Post subject: Reply with quote

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?
Back to top
Warp
Familiar Face


Joined: 24 Feb 2007
Posts: 13

PostPosted: Sat Feb 24, 2007 3:39 pm    Post subject: Reply with quote

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.
Back to top
Warp
Familiar Face


Joined: 24 Feb 2007
Posts: 13

PostPosted: Sat Feb 24, 2007 5:26 pm    Post subject: Reply with quote

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.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Sat Feb 24, 2007 5:44 pm    Post subject: Reply with quote

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.
Back to top
Warp
Familiar Face


Joined: 24 Feb 2007
Posts: 13

PostPosted: Sat Feb 24, 2007 7:26 pm    Post subject: Reply with quote

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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP