Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8792505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:59:15+00:00 2026-06-13T22:59:15+00:00

This is the same problem as in my previous question, but I moved to

  • 0

This is the same problem as in my previous question, but I moved to python3/gtk3 to be able to use a css for setting the basic properties.

From the python file:

self.w = Gtk.Window()
self.w.set_name("App")

I can use a css:

#App GtkTreeView row:selected {
    border-color: #000000;
    border-top-width: 1px;
    border-bottom-width: 1px;
    color: #000;
}

And easily permanently change the style of the selection. To me this means that I should be able to dynamically get access to the row-object and its style where I could set the bg for the Gtk.StateFlags.SELECTED.

I’ve tried a bunch of weird ways, e.g (where bg_color is a Gdk.Color that works fine for e.g. changing the style of a Label outside the TreeView).

        style=self.treeview.get_style_context()
        col = style.get_background_color(Gtk.StateFlags.SELECTED)
        col.alpha =  1.0
        col.blue = bg_color.blue
        col.red = bg_color.red
        col.green = bg_color.green

Or:

        style = self.treeview.get_style().copy()
        style.bg[Gtk.StateFlags.SELECTED] = bg_color
        self.treeview.set_style(style)

(produces error: style.bg[Gtk.StateFlags.SELECTED] = bg_color
IndexError: list assignment index out of range
)

etcetera…

So please, how do I find the way to dynamically change the selection effect depending on the normal-color of the row? Or in other words, how do I find my way to the object that actually holds the style-setting for the selection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:59:16+00:00Added an answer on June 13, 2026 at 10:59 pm

    I had one last idea about how it could be done after posting which actually ended up working:

    Reloading the css dynamically:

    In the css I added a row leaving the value for the background open to dynamic substitution:

    #App GtkTreeView row:selected {
        border-color: #400;
        border-top-width: 2px;
        border-bottom-width: 2px;
        background: {0};
        color: #000;
    }
    

    Then I loaded the css in python:

        screen = Gdk.Screen.get_default()
        self._css_provider = Gtk.CssProvider()
        css = open("notify_stack.css", 'rb')
        self._css = css.read()
        css.close()
        self._css_from = bytes("{0}".encode("utf8"))
        self._css_provider.load_from_data(self._css.replace(
            self._css_from,   
            bytes("#fff".encode("utf8"))))
        context = Gtk.StyleContext()
        context.add_provider_for_screen(screen, self._css_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    

    Later in the callback for when a row is selected I put this row (data is my ListStore):

            self._css_provider.load_from_data(
                self._css.replace(self._css_from,
                    bytes(data[rows[0]][self.BG_COLOR].encode("utf8"))))
    

    It feels really brute, there must be a nicer way, but hey it actually worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is similar to my previous question but not the same ... please
I have read the other threads regarding this same problem but I still don't
I'm having the same problem as this question . I tried installing the libcairo
I am having the same problem as this post but the answer does not
I have basically the same problem outlined in this question, however I am using
I've run into the same problem as found in this question . However, I
I 've got the same problem like in this question: SSL Error on Port
First: This is not a repeat of this question . Same script, but different
This is connected with my previous question as it's dealt with the same piece
Did ask a question about the same problem here: Silly problem with UTF8 but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.