How can I set the font name and size for a text_view? Or do I have to set the font information at the buffer or at the window? Do I have to create some sort of style-sheet?
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *view;
GtkTextBuffer *buffer;
gtk_init(&argc, &argv);
view = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_default_size(GTK_WINDOW(window), 350, 300);
gtk_container_add(GTK_CONTAINER(window), view);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
The following code works.
my.c
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget *view;
GtkTextBuffer *buffer;
GtkWidget *window;
GdkDisplay *display;
GdkScreen *screen;
GtkCssProvider *provider;
GError *error;
gtk_init(&argc, &argv);
view = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
display = gdk_display_get_default ();
screen = gdk_display_get_default_screen (display);
provider = gtk_css_provider_new();
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
error = NULL;
gtk_css_provider_load_from_file (provider, g_file_new_for_path("my.css"), &error);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_default_size(GTK_WINDOW(window), 350, 300);
gtk_container_add(GTK_CONTAINER(window), view);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
my.css
GtkTextView
{
font:Monospace 10;
}.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With