diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/layout | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/layout')
-rw-r--r-- | examples/layout/layout.cpp | 159 | ||||
-rw-r--r-- | examples/layout/layout.doc | 17 | ||||
-rw-r--r-- | examples/layout/layout.pro | 10 |
3 files changed, 186 insertions, 0 deletions
diff --git a/examples/layout/layout.cpp b/examples/layout/layout.cpp new file mode 100644 index 000000000..26f2a8d14 --- /dev/null +++ b/examples/layout/layout.cpp @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qapplication.h> +#include <qlabel.h> +#include <qcolor.h> +#include <qpushbutton.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qmultilineedit.h> +#include <qmenubar.h> +#include <qpopupmenu.h> + +class ExampleWidget : public TQWidget +{ +public: + ExampleWidget( TQWidget *parent = 0, const char *name = 0 ); + ~ExampleWidget(); +}; + +ExampleWidget::ExampleWidget( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + // Make the top-level layout; a vertical box to contain all widgets + // and sub-layouts. + TQBoxLayout *topLayout = new TQVBoxLayout( this, 5 ); + + // Create a menubar... + TQMenuBar *menubar = new TQMenuBar( this ); + menubar->setSeparator( TQMenuBar::InWindowsStyle ); + TQPopupMenu* popup; + popup = new TQPopupMenu( this ); + popup->insertItem( "&Quit", qApp, SLOT(tquit()) ); + menubar->insertItem( "&File", popup ); + + // ...and tell the layout about it. + topLayout->setMenuBar( menubar ); + + // Make an hbox that will hold a row of buttons. + TQBoxLayout *buttons = new TQHBoxLayout( topLayout ); + int i; + for ( i = 1; i <= 4; i++ ) { + TQPushButton* but = new TQPushButton( this ); + TQString s; + s.sprintf( "Button %d", i ); + but->setText( s ); + + // Set horizontal stretch factor to 10 to let the buttons + // stretch horizontally. The buttons will not stretch + // vertically, since bigWidget below will take up vertical + // stretch. + buttons->addWidget( but, 10 ); + // (Actually, the result would have been the same with a + // stretch factor of 0; if no items in a layout have non-zero + // stretch, the space is divided equally between members.) + } + + // Make another hbox that will hold a left-justified row of buttons. + TQBoxLayout *buttons2 = new TQHBoxLayout( topLayout ); + + TQPushButton* but = new TQPushButton( "Button five", this ); + buttons2->addWidget( but ); + + but = new TQPushButton( "Button 6", this ); + buttons2->addWidget( but ); + + // Fill up the rest of the hbox with stretchable space, so that + // the buttons get their minimum width and are pushed to the left. + buttons2->addStretch( 10 ); + + // Make a big widget that will grab all space in the middle. + TQMultiLineEdit *bigWidget = new TQMultiLineEdit( this ); + bigWidget->setText( "This widget will get all the remaining space" ); + bigWidget->setFrameStyle( TQFrame::Panel | TQFrame::Plain ); + + // Set vertical stretch factor to 10 to let the bigWidget stretch + // vertically. It will stretch horizontally because there are no + // widgets beside it to take up horizontal stretch. + // topLayout->addWidget( bigWidget, 10 ); + topLayout->addWidget( bigWidget ); + + // Make a grid that will hold a vertical table of TQLabel/TQLineEdit + // pairs next to a large TQMultiLineEdit. + + // Don't use hard-coded row/column numbers in TQGridLayout, you'll + // regret it when you have to change the layout. + const int numRows = 3; + const int labelCol = 0; + const int linedCol = 1; + const int multiCol = 2; + + // Let the grid-layout have a spacing of 10 pixels between + // widgets, overriding the default from topLayout. + TQGridLayout *grid = new TQGridLayout( topLayout, 0, 0, 10 ); + int row; + + for ( row = 0; row < numRows; row++ ) { + TQLineEdit *ed = new TQLineEdit( this ); + // The line edit goes in the second column + grid->addWidget( ed, row, linedCol ); + + // Make a label that is a buddy of the line edit + TQString s; + s.sprintf( "Line &%d", row+1 ); + TQLabel *label = new TQLabel( ed, s, this ); + // The label goes in the first column. + grid->addWidget( label, row, labelCol ); + } + + // The multiline edit will cover the entire vertical range of the + // grid (rows 0 to numRows) and stay in column 2. + + TQMultiLineEdit *med = new TQMultiLineEdit( this ); + grid->addMultiCellWidget( med, 0, -1, multiCol, multiCol ); + + // The labels will take the space they need. Let the remaining + // horizontal space be shared so that the multiline edit gets + // twice as much as the line edit. + grid->setColStretch( linedCol, 10 ); + grid->setColStretch( multiCol, 20 ); + + // Add a widget at the bottom. + TQLabel* sb = new TQLabel( this ); + sb->setText( "Let's pretend this is a status bar" ); + sb->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + // This widget will use all horizontal space, and have a fixed height. + + // we should have made a subclass and implemented sizePolicy there... + sb->setFixedHeight( sb->sizeHint().height() ); + + sb->setAlignment( AlignVCenter | AlignLeft ); + topLayout->addWidget( sb ); + + topLayout->activate(); +} + +ExampleWidget::~ExampleWidget() +{ + // All child widgets are deleted by TQt. + // The top-level layout and all its sub-layouts are deleted by TQt. +} + +int main( int argc, char **argv ) +{ + TQApplication a( argc, argv ); + + ExampleWidget f; + a.setMainWidget(&f); + f.setCaption("TQt Example - Layouts"); + f.show(); + + return a.exec(); +} diff --git a/examples/layout/layout.doc b/examples/layout/layout.doc new file mode 100644 index 000000000..90a7d31a3 --- /dev/null +++ b/examples/layout/layout.doc @@ -0,0 +1,17 @@ +/* +*/ +/*! \page layout-example.html + + \ingroup examples + \title Layout Managers + + This example shows simple and intermediate use of Qt's layout + classes, QGridLayout, QBoxLayout etc. + + <hr> + + Implementation: + + \include layout/layout.cpp +*/ + diff --git a/examples/layout/layout.pro b/examples/layout/layout.pro new file mode 100644 index 000000000..054b31c78 --- /dev/null +++ b/examples/layout/layout.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = layout + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = large-config + +HEADERS = +SOURCES = layout.cpp |