c++11 - 在 gtkmm 中获取小部件大小时遇到​​问题

标签 c++11 ubuntu gtk3 gtkmm3

我有一个带有 openGL 小部件的 gtk::applicationWindow。我想在创建和调整大小时查询 openGL 小部件的大小。这样做是为了补偿纵横比。这是我的代码片段。问题是当我调整或生成窗口时。 m_glAreaWidth 和 m_glAreaHeight 的值始终为 0。小部件确实会生成并对调整大小使用react,所以我不明白 get_allocation给出一个大小为 0 的矩形。

mainWindow::mainWindow(BaseObjectType* cobject ,const Glib::RefPtr<Gtk::Builder>& builder):
        Gtk::ApplicationWindow(cobject),
        m_refGlade(builder),

{

        //add GLArea Widget 
        m_TopLayout->pack_start(m_GLArea);

        m_GLArea.set_auto_render(true);

        signal_size_allocate().connect(sigc::mem_fun(*this, &mainWindow::on_my_size_allocate),false);

        //Makes window fill the whole screen
        maximize();

        show_all();

}
    void mainWindow::on_my_size_allocate(Gtk::Allocation& allocation)
{
        Gtk::Allocation glAreaAlloc = m_GLArea.get_allocation();

        m_glAreaWidth = glAreaAlloc.get_x();
        m_glAreaHeight = glAreaAlloc.get_y();


        m_GLArea.queue_render();


}

最佳答案

我想到了。我刚换了:

    Gtk::Allocation glAreaAlloc = m_GLArea.get_allocation();

    m_glAreaWidth = glAreaAlloc.get_x();
    m_glAreaHeight = glAreaAlloc.get_y();


    m_glAreaWidth = m_GLArea.get_allocated_width();
    m_glAreaHeight = m_GLArea.get_allocated_height();

仍然不确定为什么这有效,而不是另一个。

关于c++11 - 在 gtkmm 中获取小部件大小时遇到​​问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44512382/

相关文章:

linux - Linux 中的 std.net.curl 链接器错误

python-3.x - Python3 和 GTK3 出现错误 "Could not find any typelib for Gtk"

gtk3 - 在 macOS Sierra 10.12.3 上安装 GTK+ - libxml2 问题

ruby-on-rails - RVM 安装 bash 脚本什么都不做

c - 如何避免在 GTK3 应用程序中使用全局指针变量

c++ - 如何检测一个容器是否保证有序列存储

c++ - std::min() 参数中的计算是否会产生计算开销?

c++ - OpenGL光照根据观察方向改变

c++ - 为什么我会收到此错误 : 'thread' is not a member of 'std' ?

ubuntu - 应用程序未启动,出现错误 "failed to start child: Odt.Endpoint"