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 7708365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:35:38+00:00 2026-06-01T00:35:38+00:00

The following two lines of code load an image from an SVG file and

  • 0

The following two lines of code load an image from an SVG file and set it as the icon for a window:

GdkPixbuf *icon = gdk_pixbuf_new_from_file("icon.svg", NULL);
gtk_window_set_icon(GTK_WINDOW(win), icon);

This SVG file contains, among other things, a rectangle defined like:

<rect
   style="fill:#000000"
   id="screen"
   ... />

I would like to dynamically change the color of this rect element after I’ve loaded the file, but before I set it as the icon for the window.

If I manually change the style attribute on this element of the file on disk just before I start my program, it has the desired effect. But I would like to have it set by the program itself, to match a colour it has chosen.

(This is so I can distinguish multiple similar windows in the window switcher menu, among other places)

  • 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-01T00:35:40+00:00Added an answer on June 1, 2026 at 12:35 am

    I’ve now found the answer to this, from IRC (#gtk+ on irc.gnome.org), and reading GTK’s own source code.

    The answer involves building a string that sets a stylesheet and uses XML’s xinclude to pull in the original image.

    GdkPixbuf *load_icon(char *background)
    {
      /* This technique stolen from 
       *   http://git.gnome.org/browse/gtk+/tree/gtk/gtkicontheme.c#n3180
       */
    
      gchar *str = g_strconcat(
          "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
          "<svg version=\"1.1\"\n"
          "     xmlns=\"http://www.w3.org/2000/svg\"\n"
          "     xmlns:xi=\"http://www.w3.org/2001/XInclude\"\n"
          "     width=\"64\"\n"
          "     height=\"64\">\n"
          "  <style type=\"text/css\">\n"
          "    #screen {\n"
          "      fill: ", background, " !important;\n"
          "    }\n"
          "  </style>\n"
          "  <xi:include href=\"" PANGOTERM_SHAREDIR "/pangoterm.svg" "\"/>\n"
          "</svg>",
        NULL);
    
      GInputStream *stream = g_memory_input_stream_new_from_data(str, -1, g_free);
    
      GdkPixbuf *ret = gdk_pixbuf_new_from_stream(stream, NULL, NULL);
    
      g_object_unref(stream);
    
      return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two lines of code: var BadResult = (100).ToString(B, new CustomFormatter
Could someone please explain the difference between the following two lines of code: 1.
Objective-C / Cocoa: I need to load the image from a JPG file into
Take the following two lines of code: for (int i = 0; i <
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float
Possible Duplicate: How do I join two lines in vi? I have the following
While trying to execute the following lines only the last two statements are displayed(Here
I've this small snipped of code that load a file in an embedded Neo4j
I written the following code to randomly select items n items from a list
I have the following Python (3.2) code: from pygame import * class Application: def

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.