我如何将小部件与 Gtk_Grid 对齐
我这里有这个代码
Main.adb
With Gtk.Main; Use Gtk.Main;
With Gtk.Window; Use Gtk.Window;
With Gtk.Button; Use Gtk.Button;
With Gtk.Widget; Use Gtk.Widget;
With Gtk.Grid; Use Gtk.Grid;
Procedure Main is
Win : Gtk_Window;
Button : Gtk_Button;
Button2 : Gtk_Button;
Button3 : Gtk_Button;
Grid : Gtk_Grid;
begin
Init;
Gtk_New (Win);
Win.Set_Default_Size (Width => 380,
Height => 502);
Gtk_New (Button,"Button");
Gtk_New (Button2,"Button2");
Gtk_New (Button3,"Button3");
Gtk_New (Grid);
Grid.Attach (Button,0,0);
Grid.Attach (Button2,0,100);
Grid.Attach (Button3,75,20);
Win.Add (Grid);
Win.Show_All;
Gtk.Main.Main;
end Main;
我希望我的第一个按钮位于最左侧的顶部,第三个按钮位于右侧但位于底部,第二个按钮必须位于底部。我尝试了几乎所有的方法,但仍然徒劳,我无法正确对齐我的小部件,所以有人知道如何将我的所有小部件与 Gtk_Grid 对齐。
i've this code
Main.adb
With Gtk.Main; Use Gtk.Main;
With Gtk.Window; Use Gtk.Window;
With Gtk.Button; Use Gtk.Button;
With Gtk.Widget; Use Gtk.Widget;
With Gtk.Grid; Use Gtk.Grid;
Procedure Main is
Win : Gtk_Window;
Button : Gtk_Button;
Button2 : Gtk_Button;
Button3 : Gtk_Button;
Grid : Gtk_Grid;
begin
Init;
Gtk_New (Win);
Win.Set_Default_Size (Width => 380,
Height => 502);
Gtk_New (Button,"Button");
Gtk_New (Button2,"Button2");
Gtk_New (Button3,"Button3");
Gtk_New (Grid);
Grid.Attach (Button,0,0);
Grid.Attach (Button2,0,100);
Grid.Attach (Button3,75,20);
Win.Add (Grid);
Win.Show_All;
Gtk.Main.Main;
end Main;
here I would like my first button to be at the top on the far left, my third button to the right but at the bottom and my Second button must be at the bottom. I tried almost all the methods but still in vain I can't align my widgets correctly so does anyone have an idea on how I can align all my widgets with a Gtk_Grid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需将小部件添加到单元格即可。正如评论中已经指出的,
Attach
的Top
和Left
参数表示单元格索引(行/列),而不是像素。请参阅下面带注释的示例。如果您想使用坐标来定位小部件,则可以使用 GTK 固定容器。但请注意,此容器几乎从来都不是定位小部件的良好解决方案。原则上,小部件应始终使用布局容器 HBox、VBox、Table、Grid 和 Layout 进行定位。这是为了确保正确的小部件组合,无论用户的屏幕分辨率和屏幕尺寸如何。固定小部件的描述中强调了这一点:
我添加了一个示例,显示容器小部件(网格和固定)的用法。在这些示例中,我已将 GTK 代码移至单独的包中,以便添加
Destroy_Event_Callback
,而后者将调用Gtk.Main.Main_Quit
来停止 GTK 事件循环并在关闭窗口时正确退出程序。app.adb(使用 GTK 固定,请参阅手册 和 GtkAda源)
app.adb(使用GTK Grid,请参阅手册和GtkAda来源)
app.ads
main.adb
You can just add widgets to cells. As is already stated in the comment, the
Top
andLeft
parameters ofAttach
represent the cell indices (row/column), not pixels. See the annotated example below.If you want to position a widget using coordinates, then you can use a GTK Fixed container. Be aware, however, that this container is almost never a good solution for positioning widgets; widgets should, in principle, always be positioned using layout containers HBox, VBox, Table, Grid and Layout. This is to ensure proper widget composition regardless of the screen resolution and screen size of the user. This is emphasized in the description of the Fixed widget:
I've added an example that shows the usage of both container widgets, Grid and Fixed. In these example, I've moved the GTK code into a separate package in order to add a
Destroy_Event_Callback
which in turn will callGtk.Main.Main_Quit
to stop the GTK event loop and properly exit the program when you close the window.app.adb (using GTK Fixed, see manual and GtkAda source)
app.adb (using GTK Grid, see manual and GtkAda source)
app.ads
main.adb
你好,我试图找到一个解决方案,所以我创建了一个 gtk_alignment 然后将其添加到我的 gtk_grid 但所有问题是 gtk_alignment 没有在
新代码
Main.adb
定义的位置对齐小部件我想要我的第一个按钮位于窗口的最左上角,第二个按钮位于窗口的底部。
hello here I tried to find a solution so I created a gtk_alignment then I added it to my gtk_grid but a concern in all that is that gtk_alignment does not align the widget at the defined place
here the new code
Main.adb
I want my first button to be at the very top left of the window and my second button at the bottom of the window.