Jouke
Posts: 1
Joined: Wed Aug 30, 2017 6:12 pm

gtk+css problem

Wed Aug 30, 2017 6:16 pm

Hi all,

I have a problem with gtk+ version 3.22.11 on a raspberry pi running raspbian.
Not sure if this is the right place so please tell me if I have to ask somewhere else.

I build a small test GUI with glade (see debug.glade) and a python demo (debug.py) using a css (test.css) to change the fontsize of a label.

This works fine on my PC running Ubuntu and Gtk version version 3.18.9 (see PC.png) but the font size change is ignored on my RPI (see RPI.png)

The question is: is this a GTK issue or a raspbian issue ?

Thanks for your help,

Jouke
Attachments
debug.tgz
(988 Bytes) Downloaded 64 times
PC.jpg
PC.jpg (221.71 KiB) Viewed 2126 times
RPI.png
RPI.png (211.74 KiB) Viewed 2126 times

matteohammer
Posts: 1
Joined: Sun Nov 05, 2017 4:51 pm

Re: gtk+css problem

Sun Nov 05, 2017 4:53 pm

Hi, i have the same problem. Did you solve it ?

namannik
Posts: 2
Joined: Mon Feb 12, 2018 11:33 pm

Re: gtk+css problem

Mon Feb 12, 2018 11:37 pm

Similar issue here. When attempting to apply a style from the following CSS, the font color is changed, but nothing I can do will affect the font size.

Code: Select all

label {
  color: #FF0000;
  font-size: 10px;
}

User avatar
PeterO
Posts: 4182
Joined: Sun Jul 22, 2012 4:14 pm

Re: gtk+css problem

Sun Mar 25, 2018 12:24 pm

I suspect this is another consequence of the RPI guys trying to enforce their world view on everyone ! :evil:
I need a monospaced font in a gtktextview, but nothing I've tried works. It's VERY annoying when their changes invalidate lots of tutorials and documentation etc.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 4182
Joined: Sun Jul 22, 2012 4:14 pm

Re: gtk+css problem

Sun Mar 25, 2018 1:51 pm

I've found a solution....

The key seems to be so set a high enough priority for the provider. The example I had found at
https://stackoverflow.com/questions/431 ... -text-view
used GTK_STYLE_PROVIDER_PRIORITY_APPLICATION which has a value of 600 but that didn't seem high enough to
override the theme setting
Using GTK_STYLE_PROVIDER_PRIORITY_USER (value 800) seems to do the trick !

Code: Select all

    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_USER);

    error = NULL;
    gtk_css_provider_load_from_file (provider, g_file_new_for_path("./my.css"), &error);
my.css

Code: Select all

textview {
    font-family: monospace;
}
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

namannik
Posts: 2
Joined: Mon Feb 12, 2018 11:33 pm

Re: gtk+css problem

Sun Mar 25, 2018 6:09 pm

I've found that the cause of this problem is this file:

/home/pi/.config/gtk-3.0/gtk.css

It overrides the font size set in other applications by using a * selector:

Code: Select all

* {
  ...
  font-size: 12pt;
  ...
}
By removing this section of the file, I was able to use CSS to set the font size in my own application.

User avatar
PeterO
Posts: 4182
Joined: Sun Jul 22, 2012 4:14 pm

Re: gtk+css problem

Sun Mar 25, 2018 6:22 pm

Good find. I did see that file but obviously I didn't look close enough at its contents!
But using "*" seems like a lazy method to employ.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

MaxNodehi
Posts: 1
Joined: Mon Apr 16, 2018 10:54 pm

Re: gtk+css problem

Mon Apr 16, 2018 10:58 pm

I have the same problem, but none of these solutions solved my problem. I get the font color, but not font-size neither font-family.

Return to “Graphics programming”

Who is online

Users browsing this forum: No registered users and 3 guests