无法获取小部件的高度/宽度 - gtkmm [英] Unable to get height/width of a widget - gtkmm

查看:18
本文介绍了无法获取小部件的高度/宽度 - gtkmm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 gtkmm 编写应用程序.

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.

为了实现这一点,我将小部件和标签打包到一个 VBox 中,并显示()和隐藏()它们以交换它们.

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.

我知道我可以使用 label.set_size_request(x,y),并且当我手动输入尺寸时它可以工作.但我知道,小部件的大小可能会有所不同,具体取决于使用的 Gtk 主题等.

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.

我想设置标签 与小部件的尺寸完全相同 *.但是,使用 widget.get_height()* 不起作用 - 它总是返回 1.

也许一个线索是我在主窗口的构造函数中执行此操作.

Maybe a clue will be that I do this from within the main window's constructor.

推荐答案

我在 gtkmm 方面做得不多,在 pygtk 方面做得更多.但我认为要从 get_width/get_height 获得有意义的值,必须realized 实现一个小部件,这是一个可见的 X 窗口.而且我猜你的小部件在窗口构造函数中还不可见.

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.

我建议您改用 gtk.Notebook,并隐藏其选项卡.然后 gtk.Notebook 将控制标签和自定义小部件的大小.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆