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  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QLayout Class Reference
[QtGui module]

The QLayout class is the base class of geometry managers. More...

 #include <QLayout>

Inherits QObject and QLayoutItem.

Inherited by QBoxLayout, QGridLayout, and QStackedLayout.

Public Types

  • enum SizeConstraint { SetDefaultConstraint, SetFixedSize, SetMinimumSize, SetMaximumSize, SetMinAndMaxSize, SetNoConstraint }

Properties

  • 1 property inherited from QObject

Public Functions

  • 29 public functions inherited from QObject
  • 17 public functions inherited from QLayoutItem

Static Public Members

  • 5 static public members inherited from QObject

Protected Functions

  • 7 protected functions inherited from QObject

Additional Inherited Members

  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject

Detailed Description

The QLayout class is the base class of geometry managers.

This is an abstract base class inherited by the concrete classes QBoxLayout, QGridLayout, and QStackedLayout.

For users of QLayout subclasses or of QMainWindow there is seldom any need to use the basic functions provided by QLayout, such as setSizeConstraint() or setMenuBar(). See Layout Classes for more information.

To make your own layout manager, implement the functions addItem(), sizeHint(), setGeometry(), itemAt() and takeAt(). You should also implement minimumSize() to ensure your layout isn't resized to zero size if there is too little space. To support children whose heights depend on their widths, implement hasHeightForWidth() and heightForWidth(). See the Border Layout and Flow Layout examples for more information about implementing custom layout managers.

Geometry management stops when the layout manager is deleted.

See also QLayoutItem, Layout Classes, Basic Layouts Example, Border Layout Example, and Flow Layout Example.


Member Type Documentation

enum QLayout::SizeConstraint

The possible values are:

ConstantValueDescription
QLayout::SetDefaultConstraint0The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size.
QLayout::SetFixedSize3The main widget's size is set to sizeHint(); it cannot be resized at all.
QLayout::SetMinimumSize2The main widget's minimum size is set to minimumSize(); it cannot be smaller.
QLayout::SetMaximumSize4The main widget's maximum size is set to maximumSize(); it cannot be larger.
QLayout::SetMinAndMaxSize5The main widget's minimum size is set to minimumSize() and its maximum size is set to maximumSize().
QLayout::SetNoConstraint1The widget is not constrained.

See also setSizeConstraint().


Property Documentation

sizeConstraint : SizeConstraint

This property holds the resize mode of the layout.

The default mode is SetDefaultConstraint.

Access functions:

  • SizeConstraint sizeConstraint () const
  • void setSizeConstraint ( SizeConstraint )

spacing : int

This property holds the spacing between widgets inside the layout.

If no value is explicitly set, the layout's spacing is inherited from the parent layout, or from the style settings for the parent widget.

For QGridLayout, it is possible to set different horizontal and vertical spacings using setHorizontalSpacing() and setVerticalSpacing(). In that case, spacing() returns -1.

Access functions:

  • int spacing () const
  • void setSpacing ( int )

See also contentsRect(), getContentsMargins(), QStyle::layoutSpacing(), and QStyle::pixelMetric().


Member Function Documentation

QLayout::QLayout ( QWidget * parent )

Constructs a new top-level QLayout, with parent parent. parent may not be 0.

There can be only one top-level layout for a widget. It is returned by QWidget::layout().

QLayout::QLayout ()

Constructs a new child QLayout.

This layout has to be inserted into another layout before geometry management will work.

bool QLayout::activate ()

Redoes the layout for parentWidget() if necessary.

You should generally not need to call this because it is automatically called at the most appropriate times. It returns true if the layout was redone.

See also update() and QWidget::updateGeometry().

void QLayout::addChildLayout ( QLayout * l )   [protected]

This function is called from addLayout() or insertLayout() functions in subclasses to add layout l as a sub-layout.

The only scenario in which you need to call it directly is if you implement a custom layout that supports nested layouts.

See also QBoxLayout::addLayout(), QBoxLayout::insertLayout(), and QGridLayout::addLayout().

void QLayout::addChildWidget ( QWidget * w )   [protected]

This function is called from addWidget() functions in subclasses to add w as a child widget.

If w is already in a layout, this function will give a warning and remove w from the layout. This function must therefore be called before adding w to the layout's data structure.

void QLayout::addItem ( QLayoutItem * item )   [pure virtual]

Implemented in subclasses to add an item. How it is added is specific to each subclass.

This function is not usually called in application code. To add a widget to a layout, use the addWidget() function; to add a child layout, use the addLayout() function provided by the relevant QLayout subclass.

Note: The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.

See also addWidget(), QBoxLayout::addLayout(), and QGridLayout::addLayout().

void QLayout::addWidget ( QWidget * w )

Adds widget w to this layout in a manner specific to the layout. This function uses addItem().

QRect QLayout::alignmentRect ( const QRect & r ) const   [protected]

Returns the rectangle that should be covered when the geometry of this layout is set to r, provided that this layout supports setAlignment().

The result is derived from sizeHint() and expanding(). It is never larger than r.

QSize QLayout::closestAcceptableSize ( const QWidget * widget, const QSize & size )   [static]

Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size.

QRect QLayout::contentsRect () const

Returns the layout's geometry() rectangle, but taking into account the contents margins.

This function was introduced in Qt 4.3.

See also setContentsMargins() and getContentsMargins().

int QLayout::count () const   [pure virtual]

Must be implemented in subclasses to return the number of items in the layout.

See also itemAt().

Qt::Orientations QLayout::expandingDirections () const   [virtual]

Returns whether this layout can make use of more space than sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only one dimension, whereas Qt::Vertical | Qt::Horizontal means that it wants to grow in both dimensions.

The default implementation returns Qt::Horizontal | Qt::Vertical. Subclasses reimplement it to return a meaningful value based on their child widgets's size policies.

Reimplemented from QLayoutItem.

See also sizeHint().

void QLayout::getContentsMargins ( int * left, int * top, int * right, int * bottom ) const

Extracts the left, top, right, and bottom margins used around the layout, and assigns them to *left, *top, *right, and *bottom (unless they are null pointers).

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

This function was introduced in Qt 4.3.

See also setContentsMargins(), QStyle::pixelMetric(), PM_LayoutLeftMargin, PM_LayoutTopMargin, PM_LayoutRightMargin, and PM_LayoutBottomMargin.

int QLayout::indexOf ( QWidget * widget ) const   [virtual]

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

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

The default implementation iterates over all items using itemAt()

bool QLayout::isEnabled () const

Returns true if the layout is enabled; otherwise returns false.

See also setEnabled().

QLayoutItem * QLayout::itemAt ( int index ) const   [pure virtual]

Must be implemented in subclasses to return the layout item at index. If there is no such item, the function must return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.

 static void paintLayout(QPainter *painter, QLayoutItem *item)
 {
     QLayout *layout = item->layout();
     if (layout) {
         for (int i = 0; i < layout->count(); ++i)
             paintLayout(painter, layout->itemAt(i));
     }
     painter->drawRect(layout->geometry());
 }

 void MyWidget::paintEvent(QPaintEvent *)
 {
     QPainter painter(this);
     if (layout())
         paintLayout(&painter, layout());
 }

See also count() and takeAt().

QSize QLayout::maximumSize () const   [virtual]

Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar().

The default implementation allows unlimited resizing.

Reimplemented from QLayoutItem.

QWidget * QLayout::menuBar () const

Returns the menu bar set for this layout, or 0 if no menu bar is set.

See also setMenuBar().

QSize QLayout::minimumSize () const   [virtual]

Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar().

The default implementation allows unlimited resizing.

Reimplemented from QLayoutItem.

QWidget * QLayout::parentWidget () const

Returns the parent widget of this layout, or 0 if this layout is not installed on any widget.

If the layout is a sub-layout, this function returns the parent widget of the parent layout.

See also parent().

void QLayout::removeItem ( QLayoutItem * item )

Removes the layout item item from the layout. It is the caller's responsibility to delete the item.

Notice that item can be a layout (since QLayout inherits QLayoutItem).

See also removeWidget() and addItem().

void QLayout::removeWidget ( QWidget * widget )

Removes the widget widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout.

Note: The ownership of widget remains the same as when it was added.

See also removeItem(), QWidget::setGeometry(), and addWidget().

bool QLayout::setAlignment ( QWidget * w, Qt::Alignment alignment )

Sets the alignment for widget w to alignment and returns true if w is found in this layout (not including child layouts); otherwise returns false.

void QLayout::setAlignment ( Qt::Alignment alignment )

This is an overloaded member function, provided for convenience.

Sets the alignment of this item to alignment.

See also QLayoutItem::setAlignment().

bool QLayout::setAlignment ( QLayout * l, Qt::Alignment alignment )

This is an overloaded member function, provided for convenience.

Sets the alignment for the layout l to alignment and returns true if l is found in this layout (not including child layouts); otherwise returns false.

void QLayout::setContentsMargins ( int left, int top, int right, int bottom )

Sets the left, top, right, and bottom margins to use around the layout.

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

This function was introduced in Qt 4.3.

See also getContentsMargins(), QStyle::pixelMetric(), PM_LayoutLeftMargin, PM_LayoutTopMargin, PM_LayoutRightMargin, and PM_LayoutBottomMargin.

void QLayout::setEnabled ( bool enable )

Enables this layout if enable is true, otherwise disables it.

An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.

By default all layouts are enabled.

See also isEnabled().

void QLayout::setMenuBar ( QWidget * widget )

Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins(). All child widgets are placed below the bottom edge of the menu bar.

See also menuBar().

QLayoutItem * QLayout::takeAt ( int index )   [pure virtual]

Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

The following code fragment shows a safe way to remove all items from a layout:

 QLayoutItem *child;
 while ((child = layout->takeAt(0)) != 0) {
     ...
     delete child;
 }

See also itemAt() and count().

void QLayout::update ()

Updates the layout for parentWidget().

You should generally not need to call this because it is automatically called at the most appropriate times.

See also activate() and invalidate().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 72
  2. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  3. Une nouvelle ère d'IHM 3D pour les automobiles, un concept proposé par Digia et implémenté avec Qt 3
  4. Qt Creator 2.5 est sorti en beta, l'EDI supporte maintenant plus de fonctionnalités de C++11 2
  5. Vingt sociétés montrent leurs décodeurs basés sur Qt au IPTV World Forum, en en exploitant diverses facettes (déclaratif, Web, widgets) 0
  6. PySide devient un add-on Qt et rejoint le Qt Project et le modèle d'open gouvernance 1
  7. Thread travailleur avec Qt en utilisant les signaux et les slots, un article de Christophe Dumez traduit par Thibaut Cuvelier 1
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 101
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 51
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 69
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  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 » 229
  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. 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
  7. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 101
Page suivante

Le Qt Labs au hasard

Logo

Chaînes et SIMD, la revanche (de Latin1)

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. 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 4.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