1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Using a gtkmm widget</title><meta name="generator" content="DocBook XSL Stylesheets V1.64.1"><link rel="home" href="index.html" title="Programming with gtkmm2"><link rel="up" href="ch21.html" title="Chapter21.Recommended Techniques"><link rel="previous" href="ch21.html" title="Chapter21.Recommended Techniques"><link rel="next" href="ch22.html" title="Chapter22.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 gtkmm widget</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch21.html">Prev</a></td><th width="60%" align="center">Chapter21.Recommended Techniques</th><td width="20%" align="right"><a accesskey="n" href="ch22.html">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="id2520237"></a>Using a gtkmm widget</h2></div></div><div></div></div><p>
Our examples all tend to have the same structure. They follow these steps for using a Widget:
</p><p>
</p><div class="orderedlist"><ol type="1"><li><p>
Declare a variable of the type of Widget 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 <tt class="literal">new</tt> 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. <tt class="literal">Gtk::Container::add()</tt> or <tt class="literal">pack_start()</tt>.
</p></li><li><p>
Call <tt class="literal">show()</tt> to display the widget.
</p></li></ol></div><p>
</p><p>
<tt class="literal">Gtk::Widget::show()</tt> lets gtkmm know that we have finished setting the
attributes of the widget, and that it is ready to be displayed. You
can use <tt class="literal">Gtk::Widget::hide()</tt> 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="ch21.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="ch21.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="ch22.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter21.Recommended Techniques</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">Chapter22.Contributing </td></tr></table></div></body></html>
|