Why button press event only reacts on double click?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Why button press event only reacts on double click?

Klaus Rudolph
The function "signal_button_press_event()" reacts only if I double click
the button. Is it possible to react also on a single press event?



#include <iostream>
#include <gtkmm.h>
#include <gtkmm/window.h>

class ExampleWindow: public Gtk::Window
{
     Gtk::Button button;
     public:
     ExampleWindow(): button("Hallo")
     {
         add(button);
         button.signal_button_press_event().connect( [this](
GdkEventButton* ev)->bool{ std::cout << "Press" << std::endl; return
true; });
     }
};


int main(int argc, char* argv[])
{
     Gtk::Main kit(argc, argv);

     ExampleWindow window;

     window.show_all_children();
     Gtk::Main::run(window);
     return 0;
}
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Why button press event only reacts on double click?

Chris Vine-3
On Tue, 26 Dec 2017 10:56:34 +0100
Klaus Rudolph <[hidden email]> wrote:

> The function "signal_button_press_event()" reacts only if I double
> click the button. Is it possible to react also on a single press
> event?
>
> #include <iostream>
> #include <gtkmm.h>
> #include <gtkmm/window.h>
>
> class ExampleWindow: public Gtk::Window
> {
>      Gtk::Button button;
>      public:
>      ExampleWindow(): button("Hallo")
>      {
>          add(button);
>          button.signal_button_press_event().connect( [this](
> GdkEventButton* ev)->bool{ std::cout << "Press" << std::endl; return
> true; });
>      }
> };
>
>
> int main(int argc, char* argv[])
> {
>      Gtk::Main kit(argc, argv);
>
>      ExampleWindow window;
>
>      window.show_all_children();
>      Gtk::Main::run(window);
>      return 0;
> }

button-press-event is a GDK event and is concerned principally with
mouse buttons. You want the clicked signal.
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Why button press event only reacts on double click?

Kjell Ahlstedt-2
On 2017-12-26 12:03, Chris Vine wrote:
On Tue, 26 Dec 2017 10:56:34 +0100
Klaus Rudolph [hidden email] wrote:
The function "signal_button_press_event()" reacts only if I double
click the button. Is it possible to react also on a single press
event?

#include <iostream>
#include <gtkmm.h>
#include <gtkmm/window.h>

class ExampleWindow: public Gtk::Window
{
     Gtk::Button button;
     public:
     ExampleWindow(): button("Hallo")
     {
         add(button);
         button.signal_button_press_event().connect( [this]( 
GdkEventButton* ev)->bool{ std::cout << "Press" << std::endl; return 
true; });
     }
};


int main(int argc, char* argv[])
{
     Gtk::Main kit(argc, argv);

     ExampleWindow window;

     window.show_all_children();
     Gtk::Main::run(window);
     return 0;
}
button-press-event is a GDK event and is concerned principally with
mouse buttons. You want the clicked signal.

If you do prefer signal_button_press_event(), connect your signal handler so it's called before the default handler.
button.signal_button_press_event().connect(......., false);
See https://developer.gnome.org/gtkmm-tutorial/stable/sec-xeventsignals.html.en

If you connect your signal handler to run before the default signal handler, and your handler returns true, the default handler will not be called.

Kjell


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list