gpt4 book ai didi

c - 如何使用 Pango 属性设置标签的字体大小?

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:05 28 4
gpt4 key购买 nike

我正在尝试将标签添加到 GTK3 窗口,然后设置标签的字体大小。这是我的尝试:

#include <gtk/gtk.h>

static void
add_label (GtkWidget* window, gchar *text)
{

GtkWidget *label = gtk_label_new(text);
PangoAttrList *attrlist = pango_attr_list_new();
PangoAttribute *attr = pango_attr_size_new_absolute(20);
pango_attr_list_insert(attrlist, attr);
gtk_label_set_attributes(GTK_LABEL(label), attrlist);
pango_attr_list_unref(attrlist);
gtk_container_add (GTK_CONTAINER (window), label);
}

static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;

window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window1");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
add_label( window, "Hello world" );
gtk_widget_show_all (window);
}

int
main (int argc, char **argv)
{
GtkApplication *app;
int status;

app = gtk_application_new ( "org.gtk.example", G_APPLICATION_FLAGS_NONE );
g_signal_connect( app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref (app);

return status;
}

这根本不会产生任何标签。如果我注释掉这一行:

gtk_label_set_attributes(GTK_LABEL(label), attrlist);

标 checkout 现了,但是没有设置字体大小。

最佳答案

我认为这里缺少 PANGO_SCALE

PangoAttribute *attr = pango_attr_size_new_absolute(20 * PANGO_SCALE);

这应该会给你想要的结果:

enter image description here

关于c - 如何使用 Pango 属性设置标签的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48023939/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com