GNOME Bugzilla – Bug 768925
gtk_widget_get_preferred_size() returns wrong requisition when called after gtk_style_context_add_provider()
Last modified: 2017-08-06 00:43:52 UTC
Created attachment 331713 [details] Bug snippet that outputs the preferred size after clicking the "clear text" button If you run the attached snippet and click the "clear text" button, the font size will change and increase in size to 50pt. It will also output in console the requisition size after calling gtk_widget_get_preferred_size() before loading the CSS and after. My console displays that gtk_widget_get_preferred_size() does not get the updated size after loading into CSS.
You're calling: GtkStyleContext * context = gtk_widget_get_style_context (clearButton); ... gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); This will change the style context of the `clearButton` widget, but it won't change the style context of the children of `clearButton` — namely, the label. You can: * create a global CSS style provider and attach it to the screen, define style classes to it, and the add the style class to the button * associate the style provider to the actual widget that needs to use the new font size, namely the GtkLabel child of `clearButton`.
See bug 751409 where track the proposal of chaining style contexts down into children.
*** This bug has been marked as a duplicate of bug 751409 ***