Germán Diago wrote:
Hello. I'm implementing a custom widget, which is a Gtk::VBox and
contains a Gtk::Image and a label.

I want the widget to change color when the mouse goes over it (I just
want to change the VBox zone)
Looking at the documentation I found a way to change the color for
Gtk::VBox with a Gtk::EventBox, but
I don't know how to color it just when the mouse goes over it.

Any help, please?


You'll probably have to connect a slot to the Gtk::Widget::signal_{enter,leave}_notify_event() signals (see Gtk::Widget docs). See the book's signal chapter ( http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-signals-overview.html) to understand signals and the section on popup menus (http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-menus-popup.html) to see a sample handler definition that works with Gdk events.

Here is the code:

class PhotoTile : public Gtk::VBox
{
        private:
                Gtk::VBox box_;
                Gtk::Image image_;
                Gtk::Label label_;
                Gtk::EventBox evtbox_;

                std::string imagename_;

        public:

                PhotoTile()
                {
                        box_.set_spacing(12);
                        box_.set_border_width(12);
                        evtbox_.add(box_);

                        
                        evtbox_.modify_bg(Gtk::STATE_NORMAL, 
Gdk::Color("blue"));
                }

                void setImage(const std::string & imagepath)
                {
                        image_.set(imagepath);
                        box_.pack_start(image_, false, false);
                        
                        imagename_ = 
std::string(Glib::path_get_basename(imagepath), 0,
                        Glib::path_get_basename(imagepath).find_last_of('.'));
                        
                        label_.set_text("<b>" + imagename_ + "</b>");
                        label_.set_use_markup(true);
                        
                        box_.pack_start(label_, false, false);

                        pack_start(evtbox_, false, false);
                        show_all();
                }
};

And thanks for your time.
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list



--
José Alburquerque
[EMAIL PROTECTED]

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

Reply via email to