Re: Why can my window not reveive button_press signal?



> 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.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]