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