将 GtkLabel 相对于 GtkDrawingArea 对齐

发布于 2024-09-15 03:37:15 字数 136 浏览 3 评论 0原文

我在 VBox 中有一个 GtkLabel 和一个 GtkDrawingArea,我想将标签相对于 GtkDrawingArea 的 X 坐标(位于 VBox 中的标签下方)居中,我如何告诉 GTK 将该标签相对于该标签居中“锚”点 ?该点应该是标签的中心。

I have a GtkLabel and a GtkDrawingArea within a VBox, I want to center the label relative to a X-coordinate of the GtkDrawingArea (which is below of the label in the VBox), how can I tell GTK to center that label relative to that "anchor" point ? This point should be the center of the label.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧街凉风 2024-09-22 03:37:15

由于您的 GtkLabel 和 GtlDrawingArea 位于 GtkVBox 内,因此它们的位置是相对于彼此的。以下应该将标签的对齐方式设置为居中:

gtk_misc_set_alignment(GTK_MISC(label), 0.5F /*X*/, 0.5F /*Y*/);

如果您不想将 GtkLabel 的文本居中,那么您可以使用 GtkAlignment 小部件:

GtkWidget* helper;

helper = gtk_alignment_new(0.5F /*X*/, 0.5F /*Y*/, 0.0F, 0.0F);
gtk_container_add(GTK_CONTAINER(helper), label);

gtk_box_pack_start_defaults(GTK_BOX(vbox), helper);

您可以通过调用 gtk_alignment_set 函数再次重新对齐它。

Since your GtkLabel and GtlDrawingArea are inside a GtkVBox, then their position are relative to each other. The following should set the alignment of the label to the center:

gtk_misc_set_alignment(GTK_MISC(label), 0.5F /*X*/, 0.5F /*Y*/);

If you don't want to center the text of the GtkLabel, then you might use GtkAlignment widget:

GtkWidget* helper;

helper = gtk_alignment_new(0.5F /*X*/, 0.5F /*Y*/, 0.0F, 0.0F);
gtk_container_add(GTK_CONTAINER(helper), label);

gtk_box_pack_start_defaults(GTK_BOX(vbox), helper);

You can realign it again by calling gtk_alignment_set function.

您的好友蓝忘机已上羡 2024-09-22 03:37:15

我通过使用 gtk_alignment_new 解决了我的问题,以便创建居中对齐,然后使用 gtk_alignment_set_padding 来填充与任意 x 对齐所需的填充量的右侧填充- 轴值。感谢您的回答!

I solved my problem by using gtk_alignment_new in order to create a centered alignment and then I used gtk_alignment_set_padding to fill the right padding with the amount of padding needed to align with an arbitrary x-axis value. Thanks for the answers !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文