add tag
Newbyte
I have a program that reads a hexadecimal string representation from a configuration file, turns it into [a GdkRGBA struct from Gdk](https://docs.gtk.org/gdk4/method.RGBA.parse.html), uses `gtk_color_dialog_button_set_rgba ()` to set it as the default colour of a GtkColorDialogButton, and then listens to user changes to the aforementioned button.

On user change, I want to write back the chosen value to the configuration file so that it is persistent across program launches, and I need it to be a hexadecimal string representation for legacy compatibility reasons (the configuration file is `~/.Xresources`, so it needs to be compatible with many existing programs). However, while Gdk provides a [`gdk_rgba_parse ()`](https://docs.gtk.org/gdk4/method.RGBA.parse.html) function to parse a hexadecimal string representation of a colour into a GdkRGBA struct, I can't find anything to do the inverse, i.e., turn a GdkRGBA struct into a hexadecimal string representation. There is [`gdk_rgba_to_string ()`](https://docs.gtk.org/gdk4/method.RGBA.to_string.html), but it only returns strings of the form `rgb(r,g,b)` or `rgba(r,g,b,a)`, whereas I want `#rrggbb`.

How can I get the hexadecimal string representation of a GdkRGBA struct's value in C?

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.