Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The example code you show has two problems.</p> <ul> <li><p>First, you say "I have an Gtk::EventBox with two events connected." But in your example you connect to MyWindow's events, and leave the EventBox's events unconnected.</p></li> <li><p>An EventBox allows you to receive events, but you still have to explicitly say <em>which</em> events you want to receive.</p></li> </ul> <p>This is the corrected code:</p> <pre><code>#include &lt;gtkmm.h&gt; #include &lt;iostream&gt; class MyWindow : public Gtk::Window { Gtk::EventBox event_box; bool event_box_button_press(GdkEventButton *b) { std::cout &lt;&lt; "button press" &lt;&lt; std::endl; return false; } bool event_box_scroll(GdkEventScroll *e) { std::cout &lt;&lt; "scrollEvent" &lt;&lt; std::endl; return false; } public: MyWindow () { event_box.add_events(Gdk::BUTTON_MOTION_MASK); event_box.add_events(Gdk::SCROLL_MASK); event_box.signal_button_press_event().connect( sigc::mem_fun(*this, &amp;MyWindow::event_box_button_press)); event_box.signal_scroll_event().connect( sigc::mem_fun(*this, &amp;MyWindow::event_box_scroll)); add(event_box); set_default_size(640, 480); show_all(); } }; int main(int argc, char** argv) { Gtk::Main kit(argc, argv); MyWindow window; kit.run(window); return 0; } </code></pre> <p>Some notes on this code:</p> <ul> <li><p>I've omitted the ScrolledWindow, as that is irrelevant to the example. You don't need it to catch scroll events. You can add it back if you actually need a scrolled window for your application.</p></li> <li><p>The code would probably be neater if you derive a custom EventBox with the behavior you need. I didn't do this to stay closer to your original code.</p></li> <li><p>See <a href="https://developer.gnome.org/gtkmm-tutorial/3.2/sec-connecting-signal-handlers.html.en" rel="nofollow">this documentation</a> for information on connecting signals and the <code>sigc::mem_fun</code> stuff.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload