Re: [gtkmm] Gtk::Widget types



Liza Klerck <liza trdlnk com> writes:

> If I have a Gtk::Widget *, is there a way for me to check what type of
> widget it is ? I am using Gtk2.
> 
> For example:
> 
> void do_someting (Gtk::Widget *widget)
> {
>    if widget is a Gtk::Label then do this ...
>      if widget is a Gtk::Button then do this ...
>    }

Perhaps something like:

  if ((Gtk::Label *label = dynamic_cast<Gtk::Label *>(widget)))
    use "label" ...
  else if ((Gtk::Button *button = dynamic_cast<Gtk::Button *>(widget)))
    use "button" ...

The extra set of outer paranthesis kills a warning from GCC about
using = instead of ==, IIRC.

-- 
Ole Laursen
http://www.cs.auc.dk/~olau/



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