当前位置: 技术问答>linux和unix
【求助】 在 GTK+ 中如何设置控件的字体样式?
来源: 互联网 发布时间:2015-03-02
本文导语: #include void hello( GtkWidget *widget, gpointer data ) { g_print( "Hello Worldn" ); } gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { g_print( "delete event occurredn" ); return FALSE; } void destroy( GtkWidge...
#include
void hello( GtkWidget *widget, gpointer data )
{
g_print( "Hello Worldn" );
}
gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
{
g_print( "delete event occurredn" );
return FALSE;
}
void destroy( GtkWidget *widget, gpointer data )
{
gtk_main_quit();
}
int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW(window), g_locale_to_utf8("标题", 4, NULL, NULL, NULL) );
gtk_container_set_border_width( GTK_CONTAINER(window), 10 );
gtk_signal_connect( GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL );
gtk_signal_connect( GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL );
button = gtk_button_new_with_label( g_locale_to_utf8("按钮!hello!", 12, NULL, NULL, NULL) );
gtk_signal_connect( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(hello), NULL );
gtk_signal_connect_object( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(window) );
gtk_widget_set_sensitive( button, TRUE );
{
GdkFont *font = gdk_fontset_load( "stsong" );
GtkStyle *style = gtk_style_new();
gtk_style_set_font ( style, font );
gtk_widget_set_style( button, style );
/***********************************************************/
/* 问题就在这,怎么设置 button 的字体呢?stsong 就是宋体吧 */
/* 上面些设置执行时根本毫无反映,button上还是显示一堆方块 */
/* 还有,我不想使用 gettext() 国际化的方法... 谢谢! */
/***********************************************************/
}
gtk_container_add( GTK_CONTAINER(window), button );
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main();
return 0;
}
void hello( GtkWidget *widget, gpointer data )
{
g_print( "Hello Worldn" );
}
gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
{
g_print( "delete event occurredn" );
return FALSE;
}
void destroy( GtkWidget *widget, gpointer data )
{
gtk_main_quit();
}
int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW(window), g_locale_to_utf8("标题", 4, NULL, NULL, NULL) );
gtk_container_set_border_width( GTK_CONTAINER(window), 10 );
gtk_signal_connect( GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL );
gtk_signal_connect( GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL );
button = gtk_button_new_with_label( g_locale_to_utf8("按钮!hello!", 12, NULL, NULL, NULL) );
gtk_signal_connect( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(hello), NULL );
gtk_signal_connect_object( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(window) );
gtk_widget_set_sensitive( button, TRUE );
{
GdkFont *font = gdk_fontset_load( "stsong" );
GtkStyle *style = gtk_style_new();
gtk_style_set_font ( style, font );
gtk_widget_set_style( button, style );
/***********************************************************/
/* 问题就在这,怎么设置 button 的字体呢?stsong 就是宋体吧 */
/* 上面些设置执行时根本毫无反映,button上还是显示一堆方块 */
/* 还有,我不想使用 gettext() 国际化的方法... 谢谢! */
/***********************************************************/
}
gtk_container_add( GTK_CONTAINER(window), button );
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main();
return 0;
}
|
呵呵 :)