0

I am trying to edit the css of a tree view model (list store), I have set everything up using this code and it works perfectly:

auto css_provider = Gtk::CssProvider::create();
css_provider->load_from_path("style.css");

Gtk::StyleContext::add_provider_for_screen
                    (Gdk::Screen::get_default(), css_provider, 
                    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

This code successfully loads in the css file and I can change certain properties of the treeview, ive tested padding and that works fine, it applies padding to each row in the liststore:

treeview.view {
    padding: 20px;
}

or

treeview * {
    margin: 10px;
}

But if I try to reference the name of the treeview, it doesn't work (no errors or warnings):

#m_TreeView {           /* or m_TreeView.view */
    padding: 20px;
}

My main goal is to apply a margin between each row, but this also doesn't seem to work (no errors or warnings), I want to apply a margin to each row but reference the specific name of the tree view as I would have multiple tree views in my application:

treeview.view {
    margin: 20px;
}

Tried to access the rows and tried to access the list stores children (*):

treeview row {
    margin: 10px;
}

+

liststore * {
    margin: 10px;
}

1 Answer 1

0

But if I try to reference the name of the treeview, it doesn't work (no errors or warnings):

The name you need is not the variable name. To give a name for CSS styling, you can set it by calling

void Gtk::Widget::set_name  (   const Glib::ustring &   name    )   
Sign up to request clarification or add additional context in comments.

8 Comments

That works great for a widget such as a tree view but doesnt seem to work for a liststore which in my program is declared as "Glib::RefPtr<Gtk::ListStore> m_List;" also the margin css property doesnt seem to work with the rows in the ListStore but padding does
You don't set css style for ListStore, because it's meant to be used to store data only. The data it stored can be represented in a Treeview. So do css styling in Treeview, not ListStore.
ahh brilliant thank you, with the margin when I set it for the TreeViews children it adds a margin to the column names but not actually to the rows, but when I change it from margin to padding, padding is applied to both the column names and the rows
tried a bit of a hack by adding a border and setting border-spacing but I get an error when I try this
column names? Do you mean header? I tested it on my own computer, padding doesn't affect header. You can see how gtk official theme Adwaita css, gitlab.gnome.org/GNOME/gtk/-/raw/gtk-3-24/gtk/theme/Adwaita/…. There is some treeview sections inside.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.