Unable to get height/width of a widget - gtkmm

五迷三道 提交于 2020-01-01 10:54:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5396280/unable-to-get-height-width-of-a-widget-gtkmm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!