有问题获取小部件大小在gtkmm

时间:2017-06-13 04:26:31

标签: c++11 ubuntu gtk3 gtkmm3

我有一个带有openGL小部件的gtk :: applicationWindow。我想在创建和调整大小时查询openGL小部件的大小。这样做是为了补偿纵横比。这是我的代码片段。问题是当我调整窗口大小或产生窗口时。 m_glAreaWidth和m_glAreaHeight的值始终为0.小部件确实产生并响应调整大小,因此我不明白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();


}

1 个答案:

答案 0 :(得分:1)

我明白了。我刚换了:

    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();

仍然不确定为什么这样做而不是另一个。