<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Using a gtkmm widget</title> <link rel="stylesheet" href="style.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2"> <link rel="start" href="index.html" title="Programming with gtkmm"> <link rel="up" href="ch26.html" title="Chapter 26. Recommended Techniques"> <link rel="prev" href="ch26.html" title="Chapter 26. Recommended Techniques"> <link rel="next" href="ch27.html" title="Chapter 27. Contributing"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">Using a <span class="application">gtkmm</span> widget</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="ch26.html"><img src="../icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 26. Recommended Techniques</th> <td width="20%" align="right"> <a accesskey="n" href="ch27.html"><img src="../icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" lang="en"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-using_a_gtkmm_widget"></a>Using a <span class="application">gtkmm</span> widget</h2></div></div></div> <p> Our examples all tend to have the same structure. They follow these steps for using a <code class="classname">Widget</code>: </p> <p> </p> <div class="orderedlist"><ol type="1"> <li><p> Declare a variable of the type of <code class="classname">Widget</code> you wish to use, generally as member variable of a derived container class. You could also declare a pointer to the widget type, and then create it with <code class="literal">new</code> in your code. Even when using the widget via a pointer, it's still probably best to make that pointer a member variable of a container class so that you can access it later. </p></li> <li><p> Set the attributes of the widget. If the widget has no default constructor, then you will need to initialize the widget in the initalizer list of your container class's constructor. </p></li> <li><p> Connect any signals you wish to use to the appropriate handlers. </p></li> <li><p> Pack the widget into a container using the appropriate call, e.g. <code class="function">Gtk::Container::add()</code> or <code class="function">pack_start()</code>. </p></li> <li><p> Call <code class="function">show()</code> to display the widget. </p></li> </ol></div> <p> </p> <p> <code class="function">Gtk::Widget::show()</code> lets <span class="application">gtkmm</span> know that we have finished setting the attributes of the widget, and that it is ready to be displayed. You can use <code class="function">Gtk::Widget::hide()</code> to make it disappear again. The order in which you show the widgets is not important, but we do suggest that you show the top-level window last; this way, the whole window will appear with its contents already drawn. Otherwise, the user will first see a blank window, into which the widgets will be gradually drawn. </p> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="ch26.html"><img src="../icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="ch26.html"><img src="../icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="ch27.html"><img src="../icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Chapter 26. Recommended Techniques </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="../icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> Chapter 27. Contributing </td> </tr> </table> </div> </body> </html>