Gtk :: ScrolledWindow禁用滚动到焦点儿童

时间:2014-11-01 20:44:16

标签: gtk gtkmm

我在Gtk::EventBox中有一个非常大的Gtk::ScrolledWindowgrab_focus()Gtk::EventBox,{。}} Gtk::ScrolledWindow滚动到Gtk::EventBox的顶部。

如何禁用此行为?

1 个答案:

答案 0 :(得分:1)

Gtk::EventBox不会继承Gtk::Scrollable
然后用Gtk::Viewport包裹 当它被添加到Gtk::ScrolledWindow时。

要停止向焦点儿童滚动,您需要更改focus_hadjustment / focus_vadjustment

//Disable scroll to focused child
auto viewport = dynamic_cast<Gtk::Viewport*>(m_scrolled.get_child());
if (viewport) {
  auto dummy_adj = Gtk::Adjustment::create(0,0,0);
  viewport->set_focus_hadjustment(dummy_adj);
  viewport->set_focus_vadjustment(dummy_adj);
}