Which GTK+ elements support which CSS properties?

2024/9/21 11:06:25

While applying my own CSS to my GTK+ application, I noticed, that some elements ignore some CSS properties and others ignore others or don't ignore them, which leads me to search for an overview of which elements support which CSS properties.

So far I couldn't find any such overview.

For example Gtk.Label doesn't support border at all, I had to put a Gtk.Frame around it and style that in the CSS file. Another issue is, that even a Gtk.Frame doesn't support margin, which I want to use.

Can anyone give me some direction on where to find that? (Or if I am mistaken with all of this, how do I make the elements support CSS properties?)

Answer

Here is an overview of which CSS properties are supported as of GTK 3.8. The same information is mostly contained in the documentation for GtkCssProvider, albeit not in table form.

Which widgets support which properties is a bit harder. It boils down to two kinds of widgets: those that are simple and only support basic styling (no borders or backgrounds), such as GtkLabel; and those that support all properties, such as GtkFrame. Wrapping a simple widget inside a GtkFrame or GtkEventBox, as you have discovered, is the usual way to turn one into the other.

The margin property is not supported at all, and I'm told that this is a choice by the GTK developers. The thinking goes, as I understand it, that GTK is not HTML, and the layout of your widgets on screen should be governed by your code and not by CSS.

Update in GTK 3.20: The margin CSS property is now supported across most or all widgets.

https://en.xdnf.cn/q/72064.html

Related Q&A

Self import of subpackages or not?

Suppose you have the following b b/__init__.py b/c b/c/__init__.py b/c/d b/c/d/__init__.pyIn some python packages, if you import b, you only get the symbols defined in b. To access b.c, you have to exp…

why is my text not aligning properly in wxPython?

Im using wxPython to build a GUI and Im trying to align some text but its not working at all. Im trying align three different static text items in three places (right aligned, center aligned, and left …

Python subprocess check_output decoding specials characters

Im having some issues with python encoding. When I try to execute this:subprocess.check_output("ipconfig", shell=True)it gives me an output with special characters in it, like:"Statut du…

Python - SystemError: NULL result without error in PyObject call

The story: Im trying to interface from C to Python in order to use the faster computational speed of C for an existing Python code. I already had some success, also with passing NumPy arrays - but now …

Fix jumping of multiple progress bars (tqdm) in python multiprocessing

I want to parallelize a task (progresser()) for a range of input parameters (L). The progress of each task should be monitored by an individual progress bar in the terminal. Im using the tqdm package f…

How to access data stored in QModelIndex

The code below create a single QListView with the data and proxy models "attached". Clicking one of the radio buttons calls for buttonClicked() function. This function calls models .data(inde…

Pythons read and write add \x00 to the file

I have come across a weird problem when working with files in python. Lets say I have a text file and a simple piece of code that reads the contents of the file and then rewrites it with unaltered cont…

NetworkX remove attributes from a specific node

I am having a problem with networkX library in python. I build a graph that initialises some nodes, edges with attributes. I also developed a method that will dynamic add a specific attribute with a sp…

How to use Python left outer join using FOR/LIST/DICTIONARY comprehensions (not SQL)?

I have two tuples, details below:t1 = [ [aa], [ff], [er] ]t2 = [ [aa, 11,], [er, 99,] ]and I would like to get results like these below using python method similar to SQLs LEFT OUTER JOIN:res = [ [aa, …

GaussianMixture initialization using component parameters - sklearn

I want to use sklearn.mixture.GaussianMixture to store a gaussian mixture model so that I can later use it to generate samples or a value at a sample point using score_samples method. Here is an exampl…