GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 6:51 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: There is no underscore when i use gtk+ under MS windows
PostPosted: Thu Jun 19, 2008 5:52 pm 
Offline
Familiar Face

Joined: Sat Jun 07, 2008 2:31 pm
Posts: 34
Location: Hangzhou, ZheJiang, China
environment: windows xp, visual c++ 6.0 (C language)
I comipled a example called "label " from GTK+-tutorial. When I run the executable file, it might run correctly except no underscore. But under FreeBSD + gnome, it can display the underscore. Why?
Function gtk_label_set_pattern() makes the label underlined.
Thanks!
Codes:

#include <gtk/gtk.h>

int main( int argc,
char *argv[] )
{
static GtkWidget *window = NULL;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *label;

/* Initialise GTK */
gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit),
NULL);

gtk_window_set_title (GTK_WINDOW (window), "Label");
vbox = gtk_vbox_new (FALSE, 5);
hbox = gtk_hbox_new (FALSE, 5);
gtk_container_add (GTK_CONTAINER (window), hbox);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (window), 5);

frame = gtk_frame_new ("Normal Label");
label = gtk_label_new ("This is a Normal label");
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

frame = gtk_frame_new ("Multi-line Label");
label = gtk_label_new ("This is a Multi-line label.\nSecond line\n" \
"Third line");
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

frame = gtk_frame_new ("Left Justified Label");
label = gtk_label_new ("This is a Left-Justified\n" \
"Multi-line label.\nThird line");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

frame = gtk_frame_new ("Right Justified Label");
label = gtk_label_new ("This is a Right-Justified\nMulti-line label.\n" \
"Fourth line, (j/k)");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

vbox = gtk_vbox_new (FALSE, 5);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
frame = gtk_frame_new ("Line wrapped label");
label = gtk_label_new ("This is an example of a line-wrapped label. It " \
"should not be taking up the entire " /* big space to test spacing */\
"width allocated to it, but automatically " \
"wraps the words to fit. " \
"The time has come, for all good men, to come to " \
"the aid of their party. " \
"The sixth sheik's six sheep's sick.\n" \
" It supports multiple paragraphs correctly, " \
"and correctly adds "\
"many extra spaces. ");
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

frame = gtk_frame_new ("Filled, wrapped label");
label = gtk_label_new ("This is an example of a line-wrapped, filled label. " \
"It should be taking "\
"up the entire width allocated to it. " \
"Here is a sentence to prove "\
"my point. Here is another sentence. "\
"Here comes the sun, do de do de do.\n"\
" This is a new paragraph.\n"\
" This is another newer, longer, better " \
"paragraph. It is coming to an end, "\
"unfortunately.");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_FILL);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

frame = gtk_frame_new ("Underlined label");
label = gtk_label_new ("This label is underlined!\n"
"This one is underlined in quite a funky fashion");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_label_set_pattern (GTK_LABEL (label), "_________________________ _ _________ _ ______ __ _______ ___");
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

gtk_widget_show_all (window);

gtk_main ();

return 0;
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 19, 2008 6:26 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
try using gtk_label_set_markup instead:
Code:
label = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(label), "<u>This label is underlined!</u>");

you can do more with set_markup too, see here:
http://library.gnome.org/devel/pango/st ... ormat.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 20, 2008 12:45 pm 
Offline
Familiar Face

Joined: Sat Jun 07, 2008 2:31 pm
Posts: 34
Location: Hangzhou, ZheJiang, China
dreblen wrote:
try using gtk_label_set_markup instead:
Code:
label = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(label), "<u>This label is underlined!</u>");

you can do more with set_markup too, see here:
http://library.gnome.org/devel/pango/st ... ormat.html

Thanks, dreblen. I have tried using gtk_label_set_markup, and it works now. This way is better than using gtk_label_set_pattern.
I'm a novice at gtk+ programming, and i haven't studied pango lib.
I have yet another question to ask. Why it works when i using gtk_label_set_pattern under gnome(I am from China, I have set LANG zh_CN.UTF-8.)while it doesn't work under windows.


Last edited by gtkguan on Mon Jun 23, 2008 10:39 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 20, 2008 3:28 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
it might have something to do with the wimp Gtk+ engine (which is what is used on windows I believe),
gtk_label_set_pattern() stopped working for me in Gtk+ 2.10, while it worked fine in 2.8,
I'm actually kind of surprised that it's not deprecated in favor of _set_markup()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 10:42 am 
Offline
Familiar Face

Joined: Sat Jun 07, 2008 2:31 pm
Posts: 34
Location: Hangzhou, ZheJiang, China
Thanks!
The version of GTK+ I have installed is 2.12.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


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