问题描述
我写了一个使用gtkmm的应用程序。我写了一个简单的窗口小部件类,我只想在某些情况下显示在应用程序的主窗口中。否则,我希望标签禁用可见。
为了实现这个功能,我将Widget和标签打包到一个VBox中,并且显示()和隐藏()它们以便交换它们。
但是,自定义小部件远远大于标签,因此我需要调整标签的大小。
我知道我可以使用label.set_size_request(x,y),并且它可以工作,当我手动输入尺寸时。但我知道,这个小部件的大小可能会有所不同,具体取决于使用的Gtk主题等。
我喜欢设置标签 与窗口小部件具有完全相同的大小 *。然而,使用widget.get_height()* 不起作用 - 它总是返回1。
也许一个线索就是我在主窗口的构造函数中做到这一点。
get_width
/ get_height
获得有意义的值,必须实现一个窗口小部件 ,这是一个可视的X窗口。我猜你的窗口小部件在窗口构造函数中是不可见的。 我建议你使用gtk.Notebook,而隐藏它的选项卡。然后gtk.Notebook将控制您的标签和您的自定义小部件的大小。
I'm writing an application using gtkmm.
I wrote a simple widget class, that I want to display in the application's main window only in some cases. Otherwise, I would like a Label "disabled" to be visible.
To achieve that I packed both the widget and the label into one VBox, and I show() and hide() them in order to swap them.
However, the custom widget is far larger than the label, so I need to resize the label a bit.
I know I can use label.set_size_request(x,y), and it works, when I type the dimensions manually. But I am aware, that the widget may differ in size a bit, depending on the Gtk theme one uses, etc.
I'd love to set label exactly the same size *as the widget has. However, using widget.get_height()* does not work - it always returns 1.
Maybe a clue will be that I do this from within the main window's constructor.
I haven't done much in gtkmm, more in pygtk. But I think to get meaningful values from get_width
/get_height
, a widget must be realized, which is an X-window speak for visible. And I guess your widgets are not yet visible in window constructor.
I'd propose you to use a gtk.Notebook instead, with its tabs hidden. Then gtk.Notebook will control size of both your label and your custom widget.
这篇关于无法获取小部件的高度/宽度 - gtkmm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!