summaryrefslogtreecommitdiffstats
path: root/doc/html/tutorial2-09.html
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
commitbd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch)
tree7a520322212d48ebcb9fbe1087e7fca28b76185c /doc/html/tutorial2-09.html
downloadqt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz
qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip
Add Qt3 development HEAD version
Diffstat (limited to 'doc/html/tutorial2-09.html')
-rw-r--r--doc/html/tutorial2-09.html249
1 files changed, 249 insertions, 0 deletions
diff --git a/doc/html/tutorial2-09.html b/doc/html/tutorial2-09.html
new file mode 100644
index 0000000..5646d34
--- /dev/null
+++ b/doc/html/tutorial2-09.html
@@ -0,0 +1,249 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/tutorial2.doc:1233 -->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Setting Options</title>
+<style type="text/css"><!--
+fn { margin-left: 1cm; text-indent: -1cm; }
+a:link { color: #004faf; text-decoration: none }
+a:visited { color: #672967; text-decoration: none }
+body { background: #ffffff; color: black; }
+--></style>
+</head>
+<body>
+
+<table border="0" cellpadding="0" cellspacing="0" width="100%">
+<tr bgcolor="#E5E5E5">
+<td valign=center>
+ <a href="index.html">
+<font color="#004faf">Home</font></a>
+ | <a href="classes.html">
+<font color="#004faf">All&nbsp;Classes</font></a>
+ | <a href="mainclasses.html">
+<font color="#004faf">Main&nbsp;Classes</font></a>
+ | <a href="annotated.html">
+<font color="#004faf">Annotated</font></a>
+ | <a href="groups.html">
+<font color="#004faf">Grouped&nbsp;Classes</font></a>
+ | <a href="functions.html">
+<font color="#004faf">Functions</font></a>
+</td>
+<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Setting Options</h1>
+
+
+<p>
+<p> <center><img src="chart-options.png" alt="The options dialog"></center>
+<p> We provide an options dialog so that the user can set options that
+apply to all data sets in one place.
+<p> (Extracts from <tt>optionsform.h</tt>.)
+<p>
+
+<pre> class OptionsForm : public <a href="qdialog.html">QDialog</a>
+ {
+ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
+ public:
+ OptionsForm( <a href="qwidget.html">QWidget</a>* parent = 0, const char* name = "options form",
+ bool modal = FALSE, WFlags f = 0 );
+ ~OptionsForm() {}
+
+ <a href="qfont.html">QFont</a> font() const { return m_font; }
+ void setFont( <a href="qfont.html">QFont</a> font );
+
+ <a href="qlabel.html">QLabel</a> *chartTypeTextLabel;
+ <a href="qcombobox.html">QComboBox</a> *chartTypeComboBox;
+ <a href="qpushbutton.html">QPushButton</a> *fontPushButton;
+ <a href="qlabel.html">QLabel</a> *fontTextLabel;
+ <a href="qframe.html">QFrame</a> *addValuesFrame;
+ <a href="qbuttongroup.html">QButtonGroup</a> *addValuesButtonGroup;
+ <a href="qradiobutton.html">QRadioButton</a> *noRadioButton;
+ <a href="qradiobutton.html">QRadioButton</a> *yesRadioButton;
+ <a href="qradiobutton.html">QRadioButton</a> *asPercentageRadioButton;
+ <a href="qlabel.html">QLabel</a> *decimalPlacesTextLabel;
+ <a href="qspinbox.html">QSpinBox</a> *decimalPlacesSpinBox;
+ <a href="qpushbutton.html">QPushButton</a> *okPushButton;
+ <a href="qpushbutton.html">QPushButton</a> *cancelPushButton;
+
+ protected slots:
+ void chooseFont();
+
+ protected:
+ <a href="qvboxlayout.html">QVBoxLayout</a> *optionsFormLayout;
+ <a href="qhboxlayout.html">QHBoxLayout</a> *chartTypeLayout;
+ <a href="qhboxlayout.html">QHBoxLayout</a> *fontLayout;
+ <a href="qvboxlayout.html">QVBoxLayout</a> *addValuesFrameLayout;
+ <a href="qvboxlayout.html">QVBoxLayout</a> *addValuesButtonGroupLayout;
+ <a href="qhboxlayout.html">QHBoxLayout</a> *decimalPlacesLayout;
+ <a href="qhboxlayout.html">QHBoxLayout</a> *buttonsLayout;
+
+ private:
+ <a href="qfont.html">QFont</a> m_font;
+ };
+</pre>
+<p> The layout of this dialog is slightly more complicated than for the
+set data form, but we only need a single slot. Unlike the "smart" set
+data form this is a "dumb" dialog that simply provides the widgets for
+the caller to set and read. The caller is responsible for updating
+things based on the changes the user makes.
+<p> (Extracts from <tt>optionsform.cpp</tt>.)
+<p>
+
+<pre> #include "images/options_horizontalbarchart.xpm"
+ #include "images/options_piechart.xpm"
+ #include "images/options_verticalbarchart.xpm"
+</pre>
+<p> We include some some pixmaps to use in the chart type combobox.
+<p> <h2> The Constructor
+</h2>
+<a name="1"></a><p> <pre> OptionsForm::OptionsForm( <a href="qwidget.html">QWidget</a>* parent, const char* name,
+ bool modal, WFlags f )
+ : <a href="qdialog.html">QDialog</a>( parent, name, modal, f )
+ {
+ <a href="qwidget.html#setCaption">setCaption</a>( "Chart -- Options" );
+ <a href="qwidget.html#resize">resize</a>( 320, 290 );
+</pre>
+<p> We pass all the arguments on to the <a href="qdialog.html">QDialog</a> constructor, set a caption
+and set an initial size.
+<p> The layout of the form will be to have the chart type label and combo
+box in a horizontal box layout, and similarly for the font button and
+font label, and for the decimal places label and spinbox. The
+buttons will also be placed in a horizontal layout, but with a spacer
+to move them to the right. The show values radio buttons will be
+vertically aligned within a frame. All of these will be laid out in a
+vertical box layout.
+<p> <pre> optionsFormLayout = new <a href="qvboxlayout.html">QVBoxLayout</a>( this, 11, 6 );
+</pre>
+<p> All the widgets will be laid out within the form's vertical box layout.
+<p> <pre> chartTypeLayout = new <a href="qhboxlayout.html">QHBoxLayout</a>( 0, 0, 6 );
+</pre>
+<p> The chart type label and combobox will be laid out side by side.
+<p> <pre> chartTypeTextLabel = new <a href="qlabel.html">QLabel</a>( "&amp;Chart Type", this );
+ <a name="x2631"></a> chartTypeLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( chartTypeTextLabel );
+
+ chartTypeComboBox = new <a href="qcombobox.html">QComboBox</a>( FALSE, this );
+ <a name="x2633"></a> chartTypeComboBox-&gt;<a href="qcombobox.html#insertItem">insertItem</a>( QPixmap( options_piechart ), "Pie Chart" );
+ chartTypeComboBox-&gt;<a href="qcombobox.html#insertItem">insertItem</a>( QPixmap( options_verticalbarchart ),
+ "Vertical Bar Chart" );
+ chartTypeComboBox-&gt;<a href="qcombobox.html#insertItem">insertItem</a>( QPixmap( options_horizontalbarchart ),
+ "Horizontal Bar Chart" );
+ chartTypeLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( chartTypeComboBox );
+ <a name="x2630"></a> optionsFormLayout-&gt;<a href="qboxlayout.html#addLayout">addLayout</a>( chartTypeLayout );
+</pre>
+<p> We create the chart type label (with an accelerator which we'll relate
+to the chart type combobox later). We also create a chart type
+combobox, populating it with both pixmaps and text. We add them both
+to the horizontal layout and add the horizontal layout to the form's
+vertical layout.
+<p> <pre> fontLayout = new <a href="qhboxlayout.html">QHBoxLayout</a>( 0, 0, 6 );
+
+ fontPushButton = new <a href="qpushbutton.html">QPushButton</a>( "&amp;Font...", this );
+ fontLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( fontPushButton );
+ <a href="qspaceritem.html">QSpacerItem</a>* spacer = new <a href="qspaceritem.html">QSpacerItem</a>( 0, 0,
+ QSizePolicy::Expanding,
+ QSizePolicy::Minimum );
+ <a name="x2629"></a> fontLayout-&gt;<a href="qboxlayout.html#addItem">addItem</a>( spacer );
+
+ fontTextLabel = new <a href="qlabel.html">QLabel</a>( this ); // Must be set by caller via setFont()
+ fontLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( fontTextLabel );
+ optionsFormLayout-&gt;<a href="qboxlayout.html#addLayout">addLayout</a>( fontLayout );
+</pre>
+<p> We create a horizontal box layout to hold the font button and font
+label. The font button is straight-forward. We add a spacer to improve
+the appearance. The font text label is initially empty (since we don't
+know what font the user is using).
+<p> <pre> addValuesFrame = new <a href="qframe.html">QFrame</a>( this );
+ <a name="x2640"></a> addValuesFrame-&gt;<a href="qframe.html#setFrameShape">setFrameShape</a>( QFrame::StyledPanel );
+ <a name="x2639"></a> addValuesFrame-&gt;<a href="qframe.html#setFrameShadow">setFrameShadow</a>( QFrame::Sunken );
+ addValuesFrameLayout = new <a href="qvboxlayout.html">QVBoxLayout</a>( addValuesFrame, 11, 6 );
+
+ addValuesButtonGroup = new <a href="qbuttongroup.html">QButtonGroup</a>( "Show Values", addValuesFrame );
+ <a name="x2641"></a> addValuesButtonGroup-&gt;<a href="qgroupbox.html#setColumnLayout">setColumnLayout</a>(0, Qt::Vertical );
+ <a name="x2647"></a> addValuesButtonGroup-&gt;<a href="qwidget.html#layout">layout</a>()-&gt;setSpacing( 6 );
+ addValuesButtonGroup-&gt;<a href="qwidget.html#layout">layout</a>()-&gt;setMargin( 11 );
+ addValuesButtonGroupLayout = new <a href="qvboxlayout.html">QVBoxLayout</a>(
+ addValuesButtonGroup-&gt;<a href="qwidget.html#layout">layout</a>() );
+ <a name="x2644"></a> addValuesButtonGroupLayout-&gt;<a href="qlayoutitem.html#setAlignment">setAlignment</a>( Qt::AlignTop );
+
+ noRadioButton = new <a href="qradiobutton.html">QRadioButton</a>( "&amp;No", addValuesButtonGroup );
+ <a name="x2645"></a> noRadioButton-&gt;<a href="qradiobutton.html#setChecked">setChecked</a>( TRUE );
+ addValuesButtonGroupLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( noRadioButton );
+
+ yesRadioButton = new <a href="qradiobutton.html">QRadioButton</a>( "&amp;Yes", addValuesButtonGroup );
+ addValuesButtonGroupLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( yesRadioButton );
+
+ asPercentageRadioButton = new <a href="qradiobutton.html">QRadioButton</a>( "As &amp;Percentage",
+ addValuesButtonGroup );
+ addValuesButtonGroupLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( asPercentageRadioButton );
+ addValuesFrameLayout-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( addValuesButtonGroup );
+</pre>
+<p> The user may opt to display their own labels as they are or to add the
+values at the end of each label, either as-is or as percentages.
+<p> We create a frame to present the radio buttons in and create a layout
+for them. We create a button group (so that Qt will take care of
+handling the exclusive radio button behaviour automatically). Next we
+create the radio buttons, making "No" the default.
+<p> The decimal places label and spin box are laid out just like the other
+horizontal layouts, and the buttons are laid out in a very similar way
+to the buttons in the set data form.
+<p> <pre> <a href="qobject.html#connect">connect</a>( fontPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( chooseFont() ) );
+ <a href="qobject.html#connect">connect</a>( okPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( <a href="qdialog.html#accept">accept</a>() ) );
+ <a href="qobject.html#connect">connect</a>( cancelPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( <a href="qdialog.html#reject">reject</a>() ) );
+</pre>
+<p> We only need three connections:
+<ol type=1>
+<li> When the user clicks the font button we execute our own
+chooseFont() slot.
+<li> If the user clicks OK we call <a href="qdialog.html#accept">QDialog::accept</a>(); it is up to the
+caller to read the data from the dialog's widgets and perform any
+necessary actions.
+<li> If the user clicks Cancel we call <a href="qdialog.html#reject">QDialog::reject</a>().
+</ol>
+<p> <pre> <a name="x2642"></a> chartTypeTextLabel-&gt;<a href="qlabel.html#setBuddy">setBuddy</a>( chartTypeComboBox );
+ decimalPlacesTextLabel-&gt;<a href="qlabel.html#setBuddy">setBuddy</a>( decimalPlacesSpinBox );
+</pre>
+<p> We use the setBuddy() function to associate widgets with label
+accelerators.
+<p> <h2> The Slots
+</h2>
+<a name="2"></a><p> <pre> void OptionsForm::chooseFont()
+ {
+ bool ok;
+ <a name="x2638"></a> <a href="qfont.html">QFont</a> font = QFontDialog::<a href="qfontdialog.html#getFont">getFont</a>( &amp;ok, m_font, this );
+ if ( ok )
+ <a href="qwidget.html#setFont">setFont</a>( font );
+ }
+</pre>
+<p> When the user clicks the Font button this slot is invoked. It simply
+calls the static <a href="qfontdialog.html#getFont">QFontDialog::getFont</a>() function to obtain the user's
+choice of font. If they chose a font we call our setFont() slot which
+will present a textual description of the font in the font label.
+<p> <pre> void OptionsForm::<a href="qwidget.html#setFont">setFont</a>( <a href="qfont.html">QFont</a> font )
+ {
+ <a name="x2635"></a> <a href="qstring.html">QString</a> label = font.<a href="qfont.html#family">family</a>() + " " +
+ <a name="x2637"></a> QString::<a href="qstring.html#number">number</a>( font.<a href="qfont.html#pointSize">pointSize</a>() ) + "pt";
+ <a name="x2634"></a> if ( font.<a href="qfont.html#bold">bold</a>() )
+ label += " Bold";
+ <a name="x2636"></a> if ( font.<a href="qfont.html#italic">italic</a>() )
+ label += " Italic";
+ fontTextLabel-&gt;<a href="qlabel.html#setText">setText</a>( label );
+ m_font = font;
+ }
+</pre>
+<p> This function displays a textual description of the chosen font in the
+font label and holds a copy of the font in the <tt>m_font</tt> member. We
+need the font in a member so that we can provide a default font for
+chooseFont().
+<p> <p align="right">
+<a href="tutorial2-08.html">&laquo; Taking Data</a> |
+<a href="tutorial2.html">Contents</a> |
+<a href="tutorial2-10.html">The Project File &raquo;</a>
+</p>
+<p>
+<!-- eof -->
+<p><address><hr><div align=center>
+<table width=100% cellspacing=0 border=0><tr>
+<td>Copyright &copy; 2007
+<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
+<td align=right><div align=right>Qt 3.3.8</div>
+</table></div></address></body>
+</html>