Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QBoxLayout Class Reference


The QBoxLayout class lines up child widgets horizontally or vertically. More...

#include <qlayout.h>

Inherits QLayout.

Inherited by QHBoxLayout and QVBoxLayout.

List of all member functions.

Public Members

  • enum Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop, Down = TopToBottom, Up = BottomToTop }
  • QBoxLayout ( QWidget * parent, Direction, int border=0, int space = -1, const char * name=0 ) 
  • QBoxLayout ( QLayout * parentLayout, Direction, int space = -1, const char * name=0 ) 
  • QBoxLayout ( Direction, int space = -1, const char * name=0 ) 
  • ~QBoxLayout () 
  • virtual void addItem ( QLayoutItem * ) 
  • Direction direction () const
  • void setDirection ( Direction ) 
  • void addSpacing ( int size ) 
  • void addStretch ( int stretch = 0 ) 
  • void addWidget ( QWidget *, int stretch = 0, int alignment = 0 ) 
  • void addLayout ( QLayout * layout, int stretch = 0 ) 
  • void addStrut ( int ) 
  • void insertSpacing ( int index, int size ) 
  • void insertStretch ( int index, int stretch = 0 ) 
  • void insertWidget ( int index, QWidget * widget, int stretch = 0, int alignment = 0 ) 
  • void insertLayout ( int index, QLayout * layout, int stretch = 0 ) 
  • bool setStretchFactor ( QWidget *, int stretch ) 
  • bool setStretchFactor ( QLayout * l, int stretch ) 
  • virtual QSize sizeHint () const
  • virtual QSize minimumSize () const
  • virtual QSize maximumSize () const
  • virtual bool hasHeightForWidth () const
  • virtual int heightForWidth ( int ) const
  • virtual QSizePolicy::ExpandData expanding () const
  • virtual void invalidate () 
  • virtual void setGeometry ( const QRect & ) 
  • int findWidget ( QWidget * w ) 

Protected Members

  • void insertItem ( int index, QLayoutItem * ) 

Detailed Description

The QBoxLayout class lines up child widgets horizontally or vertically.

QBoxLayout takes the space it gets (from its parent layout or from the mainWidget()), divides it up into a row of boxes and makes each managed widget fill one box.

If the QBoxLayout is Horizontal, the boxes are beside each other, with suitable sizes. Each widget (or other box) will get at least its minimum sizes and at most its maximum size, and any excess space is shared according to the stretch factors (more about that below).

If the QBoxLayout is Vertical, the boxes are above and below each other, again with suitable sizes.

The easiest way to create a QBoxLayout is to use one of the convenience classes QHBoxLayout (for Horizontal boxes) or QVBoxLayout (for Vertical boxes). You can also use the QBoxLayout constructor directly, specifying its direction as LeftToRight, Down, RightToLeft or Up.

If the QBoxLayout is not the top-level layout (ie. is not managing all of the widget's area and children), you must add it to its parent layout before you can do anything with it. The normal way to add a layout is by calling parentLayout->addLayout().

Once you have done that, you can add boxes to the QBoxLayout using one of four functions:

  • addWidget() to add a widget to the QBoxLayout and set the widget's stretch factor. (The stretch factor is along the row of boxes.)
  • addSpacing() to create an empty box; this is one of the functions you use to create nice and spacious dialogs. See below for ways to set margins.
  • addStretch() to create an empty, stretchable box.
  • addLayout() to add a box containing another QLayout to the row and set that layout's stretch factor.

Use insertWidget(), insertSpacing(), insertStretch() or insertLayout() to insert a box at a specified position in the layout.

QBoxLayout also includes two margin widths:

  • setMargin() sets the width of the outer border. This is the width of the reserved space along each of the QBoxLayout's four sides.
  • setSpacing() sets the inter-box width. This is the width of the automatically allocated spacing between neighbouring boxes. (You can use addSpacing() to get more space at a .)

The outer border width defaults to 0, and the intra-widget width defaults to the same as the border width for a top-level layout, or to the same as the parent layout otherwise. Both can be set using arguments to the constructor.

You will almost always want to use the convenience classes for QBoxLayout: QVBoxLayout and QHBoxLayout, because of their simpler constructors.

See also the Layout overview documentation

Examples: layout/layout.cpp customlayout/main.cpp popup/popup.cpp


Member Type Documentation

QBoxLayout::Direction

This type is used to determine the direction of a box layout. The possible values are:

  • LeftToRight - Horizontal, from left to right
  • RightToLeft - Horizontal, from right to left
  • TopToBottom - Vertical, from top to bottom
  • Down - An alias for TopToBottom
  • BottomToTop - Vertical, from bottom to top
  • Up - An alias for BottomToTop

Member Function Documentation

QBoxLayout::QBoxLayout ( Direction d, int space = -1, const char * name=0 )

If space is -1, this QBoxLayout will inherit its parent's spacing(), otherwise space is used.

You have to insert this box into another layout.

Examples: layout/layout.cpp

QBoxLayout::QBoxLayout ( QLayout * parentLayout, Direction d, int space = -1, const char * name=0 )

Constructs a new QBoxLayout with direction d and inserts it into parentLayout.

QBoxLayout::QBoxLayout ( QWidget * parent, Direction d, int border=0, int space = -1, const char * name=0 )

Constructs a new QBoxLayout with direction d and main widget parent. parent may not be 0.

border is the number of pixels between the edge of the widget and the managed children. space is the default number of pixels between neighbouring children. If space is -1 the value of border is used.

name is the internal object name

See also direction().

QBoxLayout::~QBoxLayout ()

Destructs this box.

void QBoxLayout::addItem ( QLayoutItem * item ) [virtual]

Adds item to the end of this box layout.

Reimplemented from QLayout.

void QBoxLayout::addLayout ( QLayout * layout, int stretch = 0 )

Adds layout to the end of the box, with serial stretch factor stretch.

See also insertLayout(), setAutoAdd(), addWidget() and addSpacing().

void QBoxLayout::addSpacing ( int size )

Adds a non-stretchable space with size size to the end of this box layout. QBoxLayout gives default border and spacing. This function adds additional space.

See also insertSpacing() and addStretch().

void QBoxLayout::addStretch ( int stretch = 0 )

Adds a stretchable space with zero minimum size and stretch factor stretch to the end of this box layout.

See also addSpacing().

void QBoxLayout::addStrut ( int size )

Limits the perpendicular dimension of the box (e.g. height if the box is LeftToRight) to a minimum of size. Other constraints may increase the limit.

void QBoxLayout::addWidget ( QWidget * widget, int stretch = 0, int alignment = 0 )

Adds widget to the end of this box layout, with a stretch factor stretch and alignment alignment.

The stretch factor applies only in the direction of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factor grow more.

If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved.

Alignment is specified by alignment which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.

Note: The alignment parameter is interpreted more aggressively than in previous versions of Qt. A non-default alignment now indicates that the widget should not grow to fill the available space, but should be sized according to sizeHint().

See also insertWidget(), setAutoAdd(), addLayout() and addSpacing().

Examples: layout/layout.cpp customlayout/main.cpp popup/popup.cpp scrollview/scrollview.cpp

QBoxLayout::Direction QBoxLayout::direction() const

Returns the (serial) direction of the box. addWidget() and addSpacing() work in this direction; the stretch stretches in this direction.

The directions are LeftToRight, RightToLeft, TopToBottom and BottomToTop. For the last two, the shorter aliases Down and Up are also available.

See also addWidget() and addSpacing().

QSizePolicy::ExpandData QBoxLayout::expanding() const [virtual]

Returns the expansiveness of this layout.

Reimplemented from QLayoutItem.

int QBoxLayout::findWidget ( QWidget * w )

Searches for w in this layout (not including child layouts).

Returns the index of w, or -1 if w is not found.

bool QBoxLayout::hasHeightForWidth () const [virtual]

Returns whether this layout's preferred height depends on its width.

Reimplemented from QLayoutItem.

int QBoxLayout::heightForWidth ( int w ) const [virtual]

Returns the layout's preferred height when it is w pixels wide.

Reimplemented from QLayoutItem.

void QBoxLayout::insertItem ( int index, QLayoutItem * item ) [protected]

Inserts item in this box layout at index index. If index is negative, the item is added at the end.

Warning: does not call QLayout::insertChildLayout() if item is a QLayout.

See also addItem() and findWidget().

void QBoxLayout::insertLayout ( int index, QLayout * layout, int stretch = 0 )

Inserts layout at index index, with serial stretch factor stretch. If index is negative, the layout is added at the end.

See also setAutoAdd(), insertWidget() and insertSpacing().

void QBoxLayout::insertSpacing ( int index, int size )

Inserts a non-stretchable space at index index with size size. If index is negative, the space is added at the end.

QBoxLayout gives default border and spacing. This function adds additional space.

See also insertStretch().

void QBoxLayout::insertStretch ( int index, int stretch = 0 )

Inserts a stretchable space at index index with zero minimum size and stretch factor stretch. If index is negative, the space is added at the end.

See also insertSpacing().

void QBoxLayout::insertWidget ( int index, QWidget * widget, int stretch = 0, int alignment = 0 )

Inserts widget at index index, with a stretch factor and alignment. If index is negative, the widget is added at the end.

The stretch factor applies only in the direction of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factor grow more.

If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved.

Alignment is specified by alignment which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.

Note: The alignment parameter is interpreted more aggressively than in previous versions of Qt. A non-default alignment now indicates that the widget should not grow to fill the available space, but should be sized according to sizeHint().

See also setAutoAdd(), insertLayout() and insertSpacing().

void QBoxLayout::invalidate () [virtual]

Resets cached information.

Reimplemented from QLayoutItem.

QLayoutIterator QBoxLayout::iterator () [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QLayoutItem.

QSize QBoxLayout::maximumSize () const [virtual]

Returns the maximum size needed by this box.

Reimplemented from QLayoutItem.

QSize QBoxLayout::minimumSize () const [virtual]

Returns the minimum size needed by this box.

Reimplemented from QLayoutItem.

void QBoxLayout::setDirection ( Direction direction )

Sets the direction of this layout to direction.

void QBoxLayout::setGeometry ( const QRect & r ) [virtual]

Resizes managed widgets within the rectangle r.

Reimplemented from QLayoutItem.

bool QBoxLayout::setStretchFactor ( QLayout * l, int stretch )

Sets the stretch factor for the layout l to stretch and returns TRUE, if l is found in this layout (not including child layouts).

Returns FALSE if l is not found.

bool QBoxLayout::setStretchFactor ( QWidget * w, int stretch )

Sets the stretch factor for widget w to stretch and returns TRUE, if w is found in this layout (not including child layouts).

Returns FALSE if w is not found.

QSize QBoxLayout::sizeHint () const [virtual]

Returns the preferred size of this grid.

Reimplemented from QLayoutItem.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 56
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 93
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 32
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 231
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 2.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web