- 論壇徽章:
- 0
|
【求助】 在 GTK+ 中如何設置控件的字體樣式?
- 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 就是宋體吧 */
- /* 上面些設置執(zhí)行時根本毫無反映,button上還是顯示一堆方塊 */
- /* 還有,我不想使用 gettext() 國際化的方法... 謝謝! */
- /***********************************************************/
- }
- gtk_container_add( GTK_CONTAINER(window), button );
- gtk_widget_show(button);
- gtk_widget_show(window);
- gtk_main();
- return 0;
- }
復制代碼 |
|