4

是否可以获得标签尺寸?

#include <gtk/gtk.h>

GtkWidget *mainWindow, *titleLabel, *fixedFrame;

mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

//set window default size, and request size and all stuff

fixedFrame = gtk_fixed_new();
gtk_widget_set_size_request...
gtk_container_add(GTK_CONTAINER(mainWindow), fixedFrame);

titleLabel = gtk_label_new("Welcome!");
gtk_widget_set_size_request(titleLabel, x, y);

gtk_fixed_put(GTK_FIXED(fixedFrame), titleLabel, x1, y2);

我想知道标签"Welcome"( x, y) 的大小来计算框架中的正确位置 ( x1, y1) 但我不知道该怎么做。我已经尝试在 GTK 文档中进行搜索,但没有成功。

4

1 回答 1

6

耶!我找到了一种方法,这里怎么做

#include <gtk/gtk.h>

GtkWidget *mainWindow, *titleLabel, *fixedFrame;
GtkRequisition req;

mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

//set window default size, and request size and all stuff

fixedFrame = gtk_fixed_new();
gtk_widget_set_size_request...
gtk_container_add(GTK_CONTAINER(mainWindow), fixedFrame);

titleLabel = gtk_label_new("Welcome!");
gtk_widget_size_request(titleLabel, &req);
gtk_widget_set_size_request(titleLabel, req.width, req.height);

gtk_fixed_put(GTK_FIXED(fixedFrame), titleLabel, x1, y2);
于 2012-09-21T03:14:16.167 回答