2017-06-13 93 views
0

我有gtk :: applicationWindow和openGL小部件。我想在创建和调整大小时查询openGL小部件的大小。这样做是为了补偿高宽比。这是我的代码片段。问题是,当我调整或产卵窗口。 m_glAreaWidth和m_glAreaHeight的值始终为0.该小部件确实产生并作出反应以调整大小,所以我不明白get_allocation如何给出大小为0的矩形。在gtkmm中获取小部件大小的问题

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


} 

回答

0

我想通了。我刚刚更换:

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

仍然不知道为什么这个工作,而不是其他的。