From d796c9dd933ab96ec83b9a634feedd5d32e1ba3f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 8 Nov 2011 12:31:36 -0600 Subject: Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731 --- doc/html/tutorial1-03.html | 122 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 doc/html/tutorial1-03.html (limited to 'doc/html/tutorial1-03.html') diff --git a/doc/html/tutorial1-03.html b/doc/html/tutorial1-03.html new file mode 100644 index 00000000..b7bb972d --- /dev/null +++ b/doc/html/tutorial1-03.html @@ -0,0 +1,122 @@ + + + + + +TQt Tutorial - Chapter 3: Family Values + + + + + + + +
+ +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

TQt Tutorial - Chapter 3: Family Values

+ + +

Screenshot of tutorial three
+

This example shows how to create parent and child widgets. +

We'll keep it simple and use just a single parent and a lone child. +

/****************************************************************
+**
+** TQt tutorial 3
+**
+****************************************************************/
+
+#include <qapplication.h>
+#include <qpushbutton.h>
+#include <qfont.h>
+#include <qvbox.h>
+
+int main( int argc, char **argv )
+{
+    TQApplication a( argc, argv );
+
+    TQVBox box;
+    box.resize( 200, 120 );
+
+    TQPushButton tquit( "Quit", &box );
+    tquit.setFont( TQFont( "Times", 18, TQFont::Bold ) );
+
+    TQObject::connect( &tquit, SIGNAL(clicked()), &a, SLOT(tquit()) );
+
+    a.setMainWidget( &box );
+    box.show();
+
+    return a.exec();
+}
+
+ + + +

Line-by-line Walkthrough +

+

    #include <qvbox.h>
+
+

We add an include of qvbox.h to get the layout class we'll use. +

        TQVBox box;
+
+

Here we simply create a vertical box container. The TQVBox arranges +its child widgets in a vertical row, one above the other, handing out +space according to each child's TQWidget::sizePolicy(). +

        box.resize( 200, 120 );
+
+

We set its width to 200 pixels and the height to 120 pixels. +

        TQPushButton tquit( "Quit", &box );
+
+

A child is born. +

This TQPushButton is created with both a text ("Quit") and a parent +(box). A child widget is always on top of its parent. When +displayed, it is clipped by its parent's bounds. +

The parent widget, the TQVBox, automatically adds the child centered in +its box. Because nothing else is added, the button gets all the space +the parent has. +

        box.show();
+
+

When a parent widget is shown, it will call show for all its children +(except those on which you have done an explicit TQWidget::hide()). +

Behavior +

+

The button no longer fills the entire widget. Instead, it gets a +"natural" size. This is because there is now a new top-level widget, +which uses the button's size hint and size change policy to set the +button's size and position. (See TQWidget::sizeHint() and TQWidget::setSizePolicy() for more information about these functions.) +

(See Compiling for how to create a +makefile and build the application.) +

Exercises +

+

Try resizing the window. How does the button change? What is the +button's size-change policy? What happens to the button's height if +you run the program with a bigger font? What happens if you try to +make the window really small? +

You're now ready for Chapter 4. +

[Previous tutorial] +[Next tutorial] +[Main tutorial page] +

+ +


+ +
Copyright © 2007 +TrolltechTrademarks +
TQt 3.3.8
+
+ -- cgit v1.2.1