Why can my window not reveive button_press signal?

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

Why can my window not reveive button_press signal?

jerry-6
Hi,all
I want to make a window, which will response when my mouse presses on it.
However I failed to do so when I rewrite the on_button_press_event function.
Who can explain it to me?
Thank you in advance.

The code is very simple and as following:

MAIN.CC
-----------------------------

#include <gtkmm/main.h>
#include "examplewindow.h"

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

  ExampleWindow window;
  Gtk::Main::run(window); //Shows the window and returns when it is closed.

  return 0;
}

MYWINDOW.H
----------------------------

#ifndef MY_WINDOW_H
#define MY_WINDOW_H

#include <gtkmm/window.h>


class mywindow:public Gtk::Window
{  
public:
    mywindow();
    ~mywindow();

protected:
    virtual bool on_button_press_event(GdkEventButton *e);

};

typedef mywindow gwindow;

#endif

MYWINDOW.CC
---------------------------

#include "mywindow.h"
#include <gtkmm/messagedialog.h>

mywindow::mywindow() : Gtk::Window(Gtk::WINDOW_TOPLEVEL)
{
set_title("example");
set_default_size(450,500);
set_modal(false);
property_window_position().set_value(Gtk::WIN_POS_NONE);
set_resizable(true);
property_destroy_with_parent().set_value(false);
show_all_children();
}

mywindow::~mywindow()
{
}

bool mywindow::on_button_press_event(GdkEventButton* e)
{
bool ret_val = Window::on_button_release_event(e);

Gtk::MessageDialog dialog(*this, "Running...");
dialog.run();

return ret_val;
}

_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Why can my window not reveive button_press signal?

Armin Burgmeier
Hi jerry,

As Paul Devis said: You have to tell GTK (GDK?) that you wish to handle
mouse press events. Use the add_events function from Gtk::Widget. See
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html#a2

- Armin
_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Why can my window not reveive button_press signal?

Kresimir Sojat
In reply to this post by jerry-6
> Hi,all
> I want to make a window, which will response when my mouse presses on it.
> However I failed to do so when I rewrite the on_button_press_event function.
> Who can explain it to me?
> Thank you in advance.
>
> The code is very simple and as following:
>
> MAIN.CC
> -----------------------------
>
> #include <gtkmm/main.h>
> #include "examplewindow.h"
>
> int main(int argc, char *argv[])
> {
>   Gtk::Main kit(argc, argv);
>
>   ExampleWindow window;
>   Gtk::Main::run(window); //Shows the window and returns when it is closed.
>
>   return 0;
> }
>
> MYWINDOW.H
> ----------------------------
>
> #ifndef MY_WINDOW_H
> #define MY_WINDOW_H
>
> #include <gtkmm/window.h>
>
>
> class mywindow:public Gtk::Window
> {
> public:
>     mywindow();
>     ~mywindow();
>
> protected:
>     virtual bool on_button_press_event(GdkEventButton *e);
>
> };
>
> typedef mywindow gwindow;
>
> #endif
>
> MYWINDOW.CC
> ---------------------------
>
> #include "mywindow.h"
> #include <gtkmm/messagedialog.h>
>
> mywindow::mywindow() : Gtk::Window(Gtk::WINDOW_TOPLEVEL)
> {
> set_title("example");
> set_default_size(450,500);
> set_modal(false);
> property_window_position().set_value(Gtk::WIN_POS_NONE);
> set_resizable(true);
> property_destroy_with_parent().set_value(false);
> show_all_children();
> }
>
> mywindow::~mywindow()
> {
> }
>
> bool mywindow::on_button_press_event(GdkEventButton* e)
> {
> bool ret_val = Window::on_button_release_event(e);
>
> Gtk::MessageDialog dialog(*this, "Running...");
> dialog.run();
>
> return ret_val;
> }

Try set_events(Gdk::BUTTON_PRESS_MASK) in mywindow ctor.
_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Why can my window not reveive button_press signal?

jerry-6
In reply to this post by Armin Burgmeier
Armin Burgmeier wrote:

>Hi jerry,
>
>As Paul Devis said: You have to tell GTK (GDK?) that you wish to handle
>mouse press events. Use the add_events function from Gtk::Widget. See
>http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html#a2
>
>- Armin
>_______________________________________________
>gtkmm-list mailing list
>[hidden email]
>http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>  
>
Thank you.
My problem has been solved by adding the button_press_event, however, a
new problem arised too.
When I add the button_release_event and rewrite the
on_button_release_event() function, there is no response at all.

Are button_press and button_release differently treated in gtkmm?
_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list