Gtk / Gtkmm 动态滚动

Gtk / Gtkmm Kinetic Scrolling

我正在为我的应用程序设计一个需要动态滚动的 GUI,我正在使用 GTK(来自 Qt)并且我有以下代码:

   Gtk::Window * wnd          = new Gtk::Window();
   Gtk::ScrolledWindow * scr  = new Gtk::ScrolledWindow();
   Gtk::Layout * lay          = new Gtk::Layout();
   Gtk::VBox *   vbox         = new Gtk::VBox();

   wnd->add(*scr);
   scr->add(*vbox);

   for (int i = 0; i < 20; i++)
   {
      Gtk::Button * btn = new Gtk::Button();
      btn->set_label("Click Me");

      vbox->pack_start(*btn);
      btn->show();
   }

   scr->set_kinetic_scrolling(true);

   wnd->show();
   scr->show();
   lay->show();
   vbox->show();

这就是你得到的:

这个 link 告诉我以下内容:

void Gtk::ScrolledWindow::set_kinetic_scrolling ( bool kinetic_scrolling = true )

Turns kinetic scrolling on or off.

Kinetic scrolling only applies to devices with source Gdk::SOURCE_TOUCHSCREEN.

Since gtkmm 3.4:

Parameters kinetic_scrolling true to enable kinetic scrolling.

我尝试用鼠标抓住按钮并动态滚动,但正如预期的那样,它不起作用。我还没有触摸屏,我需要用我的鼠标进行试验,有什么办法可以做到这一点吗?

我还找到了 following:

enum InputSource {
  SOURCE_MOUSE,
  SOURCE_PEN,
  SOURCE_ERASER,
  SOURCE_CURSOR,
  SOURCE_KEYBOARD,
  SOURCE_TOUCHSCREEN,
  SOURCE_TOUCHPAD,
  SOURCE_TRACKPOINT,
  SOURCE_TABLET_PAD
}
    An enumeration describing the type of an input device in general terms.

有什么方法可以模拟设备类型吗?我想看到它的工作。

你必须有一个触摸事件。使用 GtkInspector (Ctrl+Shift+I) 然后在 Visual选项卡,设置模拟触摸屏(如下图):

应该可以。 More on Gtk Inspector