# Class to Widget

**URL:** <https://www.ruby-forum.com/t/class-to-widget/116366>\
**Category:** Ruby-Gnome 2\
**Created:** [October 4, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/class-to-widget/116366 "2007-10-04T22:39:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [October 4, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/class-to-widget/116366/1 "2007-10-04T22:39:47Z")

</div>

I’d like to learn how to convert a class to a widget. Is there someone  
who can help me with this? The Ruby tutorial on this subject hasn’t  
been written yet. I’d like to write that section using listbox.rb as an  
example.

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [October 4, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/class-to-widget/116366/2 "2007-10-04T23:07:42Z")

</div>

Your class should be a child of Gtk::TreeView, not Gtk::Widget. Updated  
example attached.

Mathieu

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [October 5, 2007, 1:08am UTC](https://www.ruby-forum.com/t/class-to-widget/116366/3 "2007-10-05T01:08:09Z")

</div>

Mathieu B. wrote:

> Your class should be a child of Gtk::TreeView, not Gtk::Widget. Updated  
> example attached.
> 
> Mathieu  
> Thanks, Mathieu! That takes care of the reason it wouldn’t run. But,  
> does the fact that TreeView is a widget automatically make ListBox a  
> widget?

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [October 5, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/class-to-widget/116366/4 "2007-10-05T17:50:33Z")

</div>

Alan L. wrote:

> Mathieu B. wrote:
> 
> Thanks, Mathieu! That takes care of the reason it wouldn’t run. But,  
> does the fact that TreeView is a widget automatically make ListBox a  
> widget?

Yes it is because Gtk::TreeView is itself a Gtk::Widget (and otherwise  
you wouldn’t be able to add your ListBox object to the window). Have a  
look at the object hierarchy of a Gtk::TreeView:

[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ATreeView](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ATreeView)

mathieu@mathieulaptop:~$ irb  
irb(main):001:0\> require “gtk2”  
=\> true  
irb(main):002:0\> Gtk::TreeView.ancestors  
=\> [Gtk::TreeView, Gtk::Container, Gtk::Widget, Atk::Implementor,  
GLib::Interface, GLib::MetaInterface, Gtk::Object,  
GLib::InitiallyUnowned, GLib::Object, GLib::Instantiatable, Object,  
Kernel]  
irb(main):003:0\> tv = Gtk::TreeView.new  
=\> #\<Gtk::TreeView:0xb67d37d0 ptr=0x8328120\>  
irb(main):004:0\> tv.is\_a? Gtk::Widget  
=\> true

HTH,  
Mathieu
