s.b
(satoshi bando)
August 9, 2023, 11:17am
1
hi, all !
Now I creating a gtk3 application by C. and I want to add “a small Button” like this:
text of button: “long-long-text”
width of button: 10px; // not enough to show a whole text
want to display like:
±------+
| lo… | ← omitted text by “…”
±------+
I tried to write C like this:
GtkWidget *button = gtk_button_new_with_label("long-long-text");
GtkStyleContext *context = gtk_widget_get_style_context(button);
GtkStyleProvider *p = GTK_STYLE_PROVIDER(gtk_css_provider_new());
gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(p),
"button {"
" min-width: 1px;"
"}"
, -1, NULL);
gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(p), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_container_add(GTK_CONTAINER(parent), button);
but above program show the whole text.
How do I specify the maximum width of button ?
dboles
August 9, 2023, 12:02pm
2
Create the label manually, use :ellipsize
as needed, and add it to the button.
You shouldn’t need a style provider here, but whenever you do, please use gtk_style_context_add_provider_for_screen()
(in GTK4, _for_display()
) because adding CSS to individual contexts is buggy and deprecated.
1 Like
s.b
(satoshi bando)
August 10, 2023, 12:15am
3
@dboles
thank you ! i’ll try that !
adding CSS to individual contexts is buggy and deprecated
oh, I dont know that. Do you have any reference for that ? (Gtk specific ? or common knowledgement of CSS ?)
ebassi
(Emmanuele Bassi)
August 10, 2023, 7:37am
4
It’s a GTK-specific limitation: adding a style provider to a widget’s specific style context does not cascade, and will not apply to any of the widget’s child.
2 Likes
s.b
(satoshi bando)
August 10, 2023, 7:43am
5
thank you for reply.
okey, I understand that!
system
(system)
Closed
September 9, 2023, 7:43am
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.