Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
查看布局容器。
在 GTK+ 中,布局几乎从不进行硬编码。与在 Windows API 中获得所需的固定大小和位置不同,GTK+ 采用不同的路线。您询问尺寸,但实际上并不能保证您能得到它。这有助于程序扩展到不同尺寸的显示器和视口。
由于没有固定的窗口大小,因此无法有固定的窗口布局。里面的小部件的排列必须是流畅的。这就是 GTK+ 容器发挥作用的地方。容器基本上是包含其他小部件的小部件。不过,它们的特别之处在于它们为您提供了如何放置小部件的很大灵活性。您可以使用
GtkVBox
来堆叠项目,使用GtkTable
为每个元素提供空间,就像 HTML 一样。 element 确实如此,甚至使用GtkFixed
来使用固定坐标系,就像在 Windows 中一样。以 GIMP 工具箱为例:您可以将窗口拉伸到不同的大小,但图标会根据窗口的新形状和大小重新排序。
此处从编码角度对容器进行了深入解释。
Glade 使得添加小部件布局容器变得相当简单。在小部件工具箱的底部,您将看到几个看起来像的图标就像成组的小按钮一样。例如,
GtkVBox
看起来像三个叠在一起的宽按钮。将其中之一添加到您的窗口中,然后添加您希望其作为子项包含的小部件。Look into layout containers.
In GTK+, layout is almost never hard coded. Unlike in the Windows API, in which you get the fixed size and location you ask for, GTK+ takes a different route. You ask for a size, but you aren't actually guaranteed to get it. This helps programs scale to different sized monitors and viewports.
Because you don't have a fixed window size, you can't have fixed window layouts. The widgets inside have to be fluid in their arrangement. This is where GTK+ containers come into play. Containers, basically, are widgets that contain other widgets. The special thing about them, though, is that they give you much flexibility in how the widgets are placed. You can use
GtkVBox
to stack items,GtkTable
to give each element space like the HTML <table> element does, or evenGtkFixed
to use a Fixed coordinate system as you would in Windows.Think of the GIMP toolbox as an example: you can stretch the window to different sizes, but the icons reorder themselves to the new shape and size of the window.
Containers are explained in-depth and from a coding perspective here.
Glade makes it rather simple to add widget layout containers. At the bottom of the widget toolbox, you will see several icons that look like groups of small buttons. For example,
GtkVBox
looks like three wide buttons on top of each other. Add one of these to your window, and add the widgets you want it to contain as children.