gpt4 book ai didi

c - 如何将 GtkWidgets 发送到后面或前面?

转载 作者:太空宇宙 更新时间:2023-11-04 03:19:25 26 4
gpt4 key购买 nike

我想知道是否有一种方法可以动态地“发送到后面”或“移到前面”GtkWidget。 (我知道,可以通过更改 GtkWidget 的创建顺序来完成)

示例:(GTK+ 2.0、Cent OS 7.0、C)

#include <gtk/gtk.h>
int main( int argc, char *argv[] )
{
GtkWidget *window, *button1, *button2, *fixed;

gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
button1 = gtk_button_new_with_label("A button");
button2 = gtk_button_new_with_label("B button");

fixed = gtk_fixed_new();

gtk_fixed_put( (GtkFixed*)fixed,button2, 30, 30 );
gtk_fixed_put( (GtkFixed*)fixed,button1, 50, 50 );
gtk_container_add(GTK_CONTAINER(window), fixed);

gtk_widget_show_all (window);
gtk_main ();
return 0;
}

this program will display : (the first picture)

A Button is over B Button是否有一些命令可以使“B 按钮”位于“A 按钮”前面。 (看起来像下面这张图 --> 第二张图)

B Button is over A Button

最佳答案

不,没有像 GtkFixed 中那样的“函数”。

来自Gtk 2 documentation :

Description

The GtkFixed widget is a container which can place child widgets at fixed positions and with fixed sizes, given in pixels. GtkFixed performs no automatic layout management.

For most applications, you should not use this container! It keeps you from having to learn about the other GTK+ containers, but it results in broken applications. With GtkFixed, the following things will result in truncated text, overlapping widgets, and other display bugs:

  • Themes, which may change widget sizes.

  • Fonts other than the one you used to write the app will of course change the size of widgets containing text; keep in mind that users may use a larger font because of difficulty reading the default, or they may be using Windows or the framebuffer port of GTK+, where different fonts are available.

  • Translation of text into other languages changes its size. Also, display of non-English text will use a different font in many cases.

In addition, the fixed widget can't properly be mirrored in right-to-left languages such as Hebrew and Arabic. i.e. normally GTK+ will flip the interface to put labels to the right of the thing they label, but it can't do that with GtkFixed. So your application will not be usable in right-to-left languages.

Finally, fixed positioning makes it kind of annoying to add/remove GUI elements, since you have to reposition all the other elements. This is a long-term maintenance problem for your application.

If you know none of these things are an issue for your application, and prefer the simplicity of GtkFixed, by all means use the widget. But you should be aware of the tradeoffs.

它们的添加顺序是它们在虚拟 Z 轴中的顺序。您可以通过删除和读取它们或其他类似方法来控制这一点。

关于c - 如何将 GtkWidgets 发送到后面或前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47902029/

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