GtkFontChooser: how does it work?

Hi, ALL,

I’m trying to use GtkFontChooser widget, but due to me not knowing how it should look/behave I have some questions.

  1. Is there an application where I can see that in action? It looks like the standard GNOME Text Editor is not supporting changing font…
  2. I tried to add this widgets to the dialog, but have an additional questions:
    2a. I’m setting the font in my application. What happen if such font is not found? Is there some kind of a default font that will be selected?
    2b. In the bottom left corner of the chooser there is a slider. What does it do?

Thank you.


You should not use Gtk.FontChooser. Instead you use one of it’s implementation like Gtk.FontButton, Gtk.FontChooserDialog, Gtk.FontChooserWidget.

  1. You can see font chooser in action using GEdit (GNOME Text Editor). Actually what you see is Gtk.FontButton which is font chooser embedded in a dialog. The dialog can be found by : Preferences > Font and Colors > Untick use system fonts > Click on Editor font.

  2. a. The font chooser lists only the fonts available in your system. So user can’t even select a font that is not installed.

  3. b. It increases or decreases the size of the font. So it helps your user in telling your application which font and what size. The slider also changes the font size in preview, so users can see how the appearance of font will be.

Hope it helps. :slight_smile:


Yes, I use GtkFontChooserWidget, sorry for the confusion.

I will check it.

As I said - it is not a user selecting a font.
It is me doing it programmatically by default (with gtk_font_chooser_set_font_desc() ).

I’m asking because when I tried to set the font to “MS Sans Serif”, the font list didn’t have any selection, but the font preview did display the string with some font. And so I figured it was using either some default font or the closest one.

So basically it is redundant, because there is a spin control on the right side, which can be used to change the size of the font.

All in all - I wish there was a screenshot of the control with some explanation in the documentation…

Thank you.

Why are you doing it ? Font chooser is for the user to select a font. For a programmer of the application, it means you will get the description of font. If you want to change the font of your application, you should tweak properties in CSS.

From the docs, Gtk.FontChooser.set_font_desc takes Pango.FontDescription as argument. So it depends on how you specify the description. In case of error, most probably it may use font of same family or default font.

Different users have different choices for giving values. The slider has markers which gives users an idea of ideal sizes.

We have. It requires some patience and experimentation. You can also use Glade and run the UI mock up. It helps in quick testing.

Anyway, you have GNOME community behind you, if you are stuck. :smiley:


Why are you doing it ? Font chooser is for the user to select a font. For a programmer of the application, it means you will get the description of font. If you want to change the font of your application, you should tweak properties in CSS.

For the better compatibility I should probably set a default font depending on the system program is running.
OTOH, if I ran on Windows and then run on Linux with GTK…

Now, what I’m looking for is set the default font and then let the user select an alternative if (s)he is not satisfied with my choice. Pretty general approach, right?

Different users have different choices for giving values. The slider has markers which gives users an idea of ideal sizes.

Pretty weird choice. I’d say make a list control with the available sizes, just like on Windows. Also would prevent user to select an unsupported size for the font. But it just me…

We have. It requires some patience and experimentation. You can also use Glade and run the UI mock up. It helps in quick testing.

Anyway, you have GNOME community behind you, if you are stuck.

Yes, thank you.

No I wish there was an easy way to modify the font…
I want my user to allow selecting underline/strikethrough fonts.

Thank you.

If they aren’t happy with with your choice of font for what?

Simple enough to do


Then just apply the appropriate pango attributes/markup


If they aren’t happy with with your choice of font for what?

For text of course - what else.

Simple enough to do

Yes, this is a possibility.
However the font chooser interface/widget is made exactly for the purpose of selecting the font USER of the program wants and it allows him/her to do the preview of such font.

The panel you show doesn’t allow have a preview and there is no familiar interface of GtkFontChooserWidget.

Thank you for a suggestion though.

BTW, how do you “Reply with Quote” here. I’m tired of copy’n’paste…

Yes okay of course it’s text, but what text? The whole app UI? Render a text file? Style a span of rich text?

Well the GtkFontButton opens a GtkFontChooserDialog with a GtkFontChooserWidget in it, but GtkFontChooser is for choosing a font not so much text decoration like underline. Of course the right approach really depends on how your using the fonts/where this selection UI is.


Click the button, it pastes it in the composer for you with the right [quote] markup for you which is really rather handy :slight_smile:

1 Like

My use case is - I have a different objects, that I show in the view. All those objects have different set of options. Those options are changeable (by user).
One object has a font that is used to display this object.

Now those options editor is done in the notebook-like interface - in Windows it is called PropertyPages and PropertySheetDialog. So when I start the program I assign the default values to those options in the objects and when the user wants he pulls up this dialog and changes those options as he likes.

So what I’m after is to create a fot property page that will have a familiar interface (like GtkFontChooserWidgets and add “Underline/Strikethrough” checkbox/switcher so that user has full control over the font.

Because it is not us - developers - who should have a final saying what font to use.

I hope I explain myself clearly.

Now in terms of “Reply With Quote” - I don’t see it. All I see is “Reply” button with some squiggly arrow.
Where did you see it?

Thank you.

Ah now what your doing makes more sense

Since these things should be instant apply you don’t need to preview it, just have an underline toggle and you can immediaetly see what it does

I can’t say I’ve ever seen an editor that has text decoration as part of the font picker, e.g. LO has them as toggles


If you really want to use FontChooserWidget directly (though I wouldn’t recommend it) rather then GtkFontButton you can do something like

See my picture, you select the text you want to quote

Yes, this is what I’m doing.

But what I’d like to do is display the selected font with the underline/strikethrough attributes in the preview window (BTW, where it is in your screenshot?)

But it looks like I will not be able to do that, because apparently GTK+ developers decides whats good for the final users of the program made by software designer.

So in the end I might consider using just a button with the extra click to just select a font face name or a different size for a font.

Seems very ugly UI if you ask me.

I would even go as far as recreate that UI by hand and add those 2 switchers, but it was seemed like a waste of resources.

In the end - I might just copy the code from the GTK (do you know if its license allows to copy the whole file in the user code?)

Thank you.

Yes, as you can see I found it.


The GTK developers provide you with common widgets for common tasks, and they conform to a consistent set of interface guidelines. If you want your application to conform to some other set of guidelines, you are definitely encouraged to write your own widgets.


Yes, I understand.
What I’m trying to do here is to extend the existing control by making it behave as I want. However it seems difficult to do, because GTK doesn’t provide access to the functionality I want.
It would be nice of course if GTK devs made that public, so that could be extended.

Thank you.

I honestly haven’t figured out what you’re trying to achieve, or why you think it’s a good idea. In general, modifying how widgets behave is not a great idea to begin with, so it’s highly unlikely we’re going to give you a gun to shoot yourself in the foot—and, by extension, to shoot your users in their feet.

Text attributes like underline or strike-through have nothing to do with selecting a font, and, thus, are out of scope when previewing a font in the font chooser. Text attributes are transient, and apply to specific sections of the text; in other words: you typically select a font, and then apply attributes on top.

If you want to mush everything together, as @zbrown showed, you could use a GtkPopover with a GtkFontChooserButton for selecting the font family, and then include additional controls for the text attributes you care about; if you want to show a preview, you can do so in those controls, for instance by changing the font description of the label, or including an additional preview label that shows the cumulative effect of every UI element—font and attributes.

1 Like


If you look at Windows and OSX, their font selection dialog both have a possibility of selecting underline/strikethrough attributes (I’m using GTK+ terminology here). So in the cross-platform application, I, as a developer, would like to give my users same functionality all across.
Also - this is not a gun. I know how to make the font underlined/striken. All I want is to allow my user a possibility to select it if they want and unselect it if they don’t.

Understood and agree if we are talking about Word processors.
If we look at MS Word it has a toolbar with icons to give the font different characteristics (bold, italic) and attributes (underline, strike-through).
However in all other instances you need the ability to see the font before applying it to the text rendering thing.

I can probably use the mockup that @zbrown showed and add the font preview below. Problem is every time the user of my program will want to change the font he will have to do the extra clicks to change it and then close the font chooser to see result.

I don’t know about you, but I would be devastated. :wink:

Thank you.

Let me start with explaining some terminology:

GTK+ core developers - they are people like you who writes and maintains GTK+ code itself.
GTK+ developers - they are people like me who creates a software that uses GTK+. We do not affiliate ourselves with GTK+ (well, some are). :wink:
GTK+ end-users - they are people that uses the software made by us (GTK+ developers), which uses GTK+ library code.

Now, GTK+ core developers cannot possibly imagine all scenarios that GTK+ developers will face. In my specific case I’m trying to create a software that will render some text alone with some shapes on the screen. It is not a text editor at all. It is more like a designer software meant for the GTK+ end-user to create an interface they will utilize.

Now what I’d like to acjieve is to give GTK+ end-users the ability to select ANY font they like. With any possible types attributes to render.

It is a very simple and easy task to do on both Windows and OSX.
On Windows there is “fontpropertypage” which allows the end-user to select the font with any characteristics and immediately see what it (s)he will get.
On OSX there is a “fontselectionpanel”, which I believe also has a “preview” and it also has the possibility of selecting any font characteristics.

However GTK+ end-users (and subsequently GTK+ developers) are very limited in this regards. They cant select the font with any characteristics and immediately see the results. It just not possible because someone made a decision - “GTK+ end-users will be very limited when they want to select the font”.

As I said - I do agree that for the text editor like MS Word or Libre Office this is OK - you just create some kind of a toolbar that will have appropriate buttons. On top of that people who do text editing do know what each font looks like with any given attributes. After all they do text editing.
But when software want to utilize font selection dialog…

Sorry for such a big post. I hope you see why I am trying to push for this.

Thank you.

[citation needed]

NSFontPanel? hmm looks like recent macOS does allow setting strikethrough/underline

But really underline/strikethrough is an attribute applied to text, it isn’t really part of the font

No, it was “decided” GtkFontChooser is about selecting a PangoFontDescription aka a font vs applying PangoAttributes to a text span (such as pango_attr_underline_new/pango_attr_strikethrough_new)

Inkscape/GIMP have very similar patterns :man_shrugging:

As far as I can tell you want a very specific pattern, and want @ebassi to implement it for you. I’m fairly certain that’s not what your going for but that is the impression I’m getting.

Well boldness and italicesed are also text attributes - they are not part of the font. The only part that characterises font is the font name - everything else is applied to the text.

As I said - every scenario/every program is different.
And when you design the library that will be widely used you might consider the possibility that someone will need it.
Besides - the control is called GtkFontChooser, not PangoFontChooser, which gives an impression that it is for choosing fonts and not font description.

No, I’m not asking anyone to implement that for me. I’m trying to state the fact that the scenario I’m trying to implement is not covered by GTK+ because someone decides its not viable scenario and therefore limits the usage of the library to a specific scenario this person wanted.

And of course my pattern is not very specific - I’m sure other software will benefit from such an extension (including text editors).

Right now - the only way to implement what I’d like is to either create an unnecessary toolbar buttons (unnecessary, because I’m not dealing with texts, but rather some object properties), or push users to do “click-select-click-select” from the layout you gave.
I would’ve been happy if the GtkFontChooser{Widget} interface would at least provide access to the preview window layout so that it can be extended from the outside if needed.
But apparently convince GTK+ core devs to change something is “Mission Impossible”. :wink:

Code does not appear by sheer magic: somebody needs to write it. Are you willing to contribute to GTK, after talking to designers?

You are the first person, according to the issue tracker, that requested this functionality.

This has no relevance: we don’t write a toolkit that allows you to write every possible program, or to cater to every possible scenario. You’re empowered to write your own font selection widget, if your needs are not covered by the widgetry provided by GTK out of the box. You’re also free to contribute back that widget to the GTK project—assuming three or more applications share your approach.

1 Like


I can try.
Problem is to convince GTK+ core devs to accept it. :wink:

That’s surprising, but OK.

I understand.
However, this “3+ application” rule is kind of weird.
If I want to extend an existing window/widget I need to confront the developers of 3 different GTK apps so that they agree on such extension. That sounds like an impossible task.

Thank you.