我有一个带有 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/