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  · 

QGraphicsLayoutItem Class Reference
[QtGui module]

The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts. More...

 #include <QGraphicsLayoutItem>

Inherited by QGraphicsLayout and QGraphicsWidget.

This class was introduced in Qt 4.4.

Public Functions

Protected Functions

  • virtual QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const = 0

Detailed Description

The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.

QGraphicsLayoutItem is an abstract class that defines a set of virtual functions describing sizes, size policies, and size hints for any object arranged by QGraphicsLayout. The API contains functions relevant for both the item itself and for the user of the item as most of QGraphicsLayoutItem's functions are also part of the subclass' public API.

In most cases, existing layout-aware classes such as QGraphicsWidget and QGraphicsLayout already provide the functionality you require. However, subclassing these classes will enable you to create both graphical elements that work well with layouts (QGraphicsWidget) or custom layouts (QGraphicsLayout).

Subclassing QGraphicsLayoutItem

If you create a subclass of QGraphicsLayoutItem and reimplement its virtual functions, you will enable the layout to resize and position your item along with other QGraphicsLayoutItems including QGraphicsWidget and QGraphicsLayout.

You can start by reimplementing important functions: the protected sizeHint() function, as well as the public setGeometry() function. If you want your items to be aware of immediate geometry changes, you can also reimplement updateGeometry().

The geometry, size hint, and size policy affect the item's size and position. Calling setGeometry() will always resize and reposition the item immediately. Normally, this function is called by QGraphicsLayout after the layout has been activated, but it can also be called by the item's user at any time.

The sizeHint() function returns the item' minimum, preferred and maximum size hints. You can override these properties by calling setMinimumSize(), setPreferredSize() or setMaximumSize(). You can also use functions such as setMinimumWidth() or setMaximumHeight() to set only the width or height component if desired.

The effectiveSizeHint() function, on the other hand, returns a size hint for any given Qt::SizeHint, and guarantees that the returned size is bound to the minimum and maximum sizes and size hints. You can set the item's vertical and horizontal size policy by calling setSizePolicy(). The sizePolicy property is used by the layout system to describe how this item prefers to grow or shrink.

Nesting QGraphicsLayoutItems

QGraphicsLayoutItems can be nested within other QGraphicsLayoutItems, similar to layouts that can contain sublayouts. This is done either by passing a QGraphicsLayoutItem pointer to QGraphicsLayoutItem's protected constructor, or by calling setParentLayoutItem(). The parentLayoutItem() function returns a pointer to the item's layoutItem parent. If the item's parent is 0 or if the the parent does not inherit from QGraphicsItem, the parentLayoutItem() function then returns 0. isLayout() returns true if the QGraphicsLayoutItem subclass is itself a layout, or false otherwise.

Qt uses QGraphicsLayoutItem to provide layout functionality in the The Graphics View Framework, but in the future its use may spread throughout Qt itself.

See also QGraphicsWidget, QGraphicsLayout, QGraphicsLinearLayout, and QGraphicsGridLayout.


Member Function Documentation

QGraphicsLayoutItem::QGraphicsLayoutItem ( QGraphicsLayoutItem * parent = 0, bool isLayout = false )

Constructs the QGraphicsLayoutItem object. parent becomes the object's parent. If isLayout is true the item is a layout, otherwise isLayout is false.

QGraphicsLayoutItem::~QGraphicsLayoutItem ()   [virtual]

Destroys the QGraphicsLayoutItem object.

QRectF QGraphicsLayoutItem::contentsRect () const

Returns the contents rect in local coordinates.

The contents rect defines the subrectangle used by an associated layout when arranging subitems. This function is a convenience function that adjusts the item's geometry() by its contents margins. Note that getContentsMargins() is a virtual function that you can reimplement to return the item's contents margins.

See also getContentsMargins() and geometry().

QSizeF QGraphicsLayoutItem::effectiveSizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const

Returns the effective size hint for this QGraphicsLayoutItem.

which is the size hint in question. constraint is an optional argument that defines a special constrain when calculating the effective size hint. By default, constraint is QSizeF(-1, -1), which means there is no constraint to the size hint.

If you want to specify the widget's size hint for a given width or height, you can provide the fixed dimension in constraint. This is useful for widgets that can grow only either vertically or horizontally, and need to set either their width or their height to a special value.

For example, a text paragraph item fit into a column width of 200 may grow vertically. You can pass QSizeF(200, -1) as a constraint to get a suitable minimum, preferred and maximum height).

You can adjust the effective size hint by reimplementing sizeHint() in a QGraphicsLayoutItem subclass, or by calling one of the following functions: setMinimumSize(), setPreferredSize, or setMaximumSize() (or a combination of both).

This function caches each of the size hints and guarantees that sizeHint() will be called only once for each value of which - unless constraint is not specified and updateGeometry() has been called.

See also sizeHint().

QRectF QGraphicsLayoutItem::geometry () const

Returns the item's geometry (e.g., position and size) as a QRectF. This function is equivalent to QRectF(pos(), size()).

See also setGeometry().

void QGraphicsLayoutItem::getContentsMargins ( qreal * left, qreal * top, qreal * right, qreal * bottom ) const   [virtual]

This virtual function provides the left, top, right and bottom contents margins for this QGraphicsLayoutItem. The default implementation assumes all contents margins are 0. The parameters point to values stored in qreals. If any of the pointers is 0, that value will not be updated.

See also QGraphicsWidget::setContentsMargins().

bool QGraphicsLayoutItem::isLayout () const

Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges other QGraphicsLayoutItem objects); otherwise returns false.

See also QGraphicsLayout.

qreal QGraphicsLayoutItem::maximumHeight () const

Returns the maximum height.

See also setMaximumHeight(), setMaximumSize(), and maximumSize().

QSizeF QGraphicsLayoutItem::maximumSize () const

Returns the maximum size.

See also setMaximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, and sizeHint().

qreal QGraphicsLayoutItem::maximumWidth () const

Returns the maximum width.

See also setMaximumWidth(), setMaximumSize(), and maximumSize().

qreal QGraphicsLayoutItem::minimumHeight () const

Returns the minimum height.

See also setMinimumHeight(), setMinimumSize(), and minimumSize().

QSizeF QGraphicsLayoutItem::minimumSize () const

Returns the minimum size.

See also setMinimumSize(), preferredSize(), maximumSize(), Qt::MinimumSize, and sizeHint().

qreal QGraphicsLayoutItem::minimumWidth () const

Returns the minimum width.

See also setMinimumWidth(), setMinimumSize(), and minimumSize().

QGraphicsLayoutItem * QGraphicsLayoutItem::parentLayoutItem () const

Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not inherit from QGraphicsLayoutItem (QGraphicsLayoutItem is often used through multiple inheritance with QObject-derived classes).

See also setParentLayoutItem().

qreal QGraphicsLayoutItem::preferredHeight () const

Returns the preferred height.

See also setPreferredHeight(), setPreferredSize(), and preferredSize().

QSizeF QGraphicsLayoutItem::preferredSize () const

Returns the preferred size.

See also setPreferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, and sizeHint().

qreal QGraphicsLayoutItem::preferredWidth () const

Returns the preferred width.

See also setPreferredWidth(), setPreferredSize(), and preferredSize().

void QGraphicsLayoutItem::setGeometry ( const QRectF & rect )   [virtual]

This pure virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordinates (e.g., the top-left corner of rect is equivalent to the item's position in parent coordinates).

Reimplement this function in a subclass of QGraphicsLayoutItem to enable your item to receive geometry updates.

If rect is outside of the bounds of minimumSize and maximumSize, it will be adjusted to its closest size so that it is within the legal bounds.

See also geometry().

void QGraphicsLayoutItem::setMaximumHeight ( qreal height )

Sets the maximum height to height.

See also maximumHeight(), setMaximumSize(), and maximumSize().

void QGraphicsLayoutItem::setMaximumSize ( const QSizeF & size )

Sets the maximum size to size. This property overrides sizeHint() for Qt::MaximumSize and ensures that effectiveSizeHint() will never return a size larger than size. In order to unset the maximum size, use an invalid size.

See also maximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, and sizeHint().

void QGraphicsLayoutItem::setMaximumSize ( qreal w, qreal h )

This is an overloaded member function, provided for convenience.

This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)).

See also maximumSize(), setMinimumSize(), setPreferredSize(), and sizeHint().

void QGraphicsLayoutItem::setMaximumWidth ( qreal width )

Sets the maximum width to width.

See also maximumWidth(), setMaximumSize(), and maximumSize().

void QGraphicsLayoutItem::setMinimumHeight ( qreal height )

Sets the minimum height to height.

See also minimumHeight(), setMinimumSize(), and minimumSize().

void QGraphicsLayoutItem::setMinimumSize ( const QSizeF & size )

Sets the minimum size to size. This property overrides sizeHint() for Qt::MinimumSize and ensures that effectiveSizeHint() will never return a size smaller than size. In order to unset the minimum size, use an invalid size.

See also minimumSize(), maximumSize(), preferredSize(), Qt::MinimumSize, sizeHint(), setMinimumWidth(), and setMinimumHeight().

void QGraphicsLayoutItem::setMinimumSize ( qreal w, qreal h )

This is an overloaded member function, provided for convenience.

This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)).

See also minimumSize(), setMaximumSize(), setPreferredSize(), and sizeHint().

void QGraphicsLayoutItem::setMinimumWidth ( qreal width )

Sets the minimum width to width.

See also minimumWidth(), setMinimumSize(), and minimumSize().

void QGraphicsLayoutItem::setParentLayoutItem ( QGraphicsLayoutItem * parent )

Sets the parent of this QGraphicsLayoutItem to parent.

See also parentLayoutItem().

void QGraphicsLayoutItem::setPreferredHeight ( qreal height )

Sets the preferred height to height.

See also preferredHeight(), preferredWidth(), setPreferredSize(), and preferredSize().

void QGraphicsLayoutItem::setPreferredSize ( const QSizeF & size )

Sets the preferred size to size. This property overrides sizeHint() for Qt::PreferredSize and provides the default value for effectiveSizeHint(). In order to unset the preferred size, use an invalid size.

See also preferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, and sizeHint().

void QGraphicsLayoutItem::setPreferredSize ( qreal w, qreal h )

This is an overloaded member function, provided for convenience.

This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)).

See also preferredSize(), setMaximumSize(), setMinimumSize(), and sizeHint().

void QGraphicsLayoutItem::setPreferredWidth ( qreal width )

Sets the preferred width to width.

See also preferredWidth(), preferredHeight(), setPreferredSize(), and preferredSize().

void QGraphicsLayoutItem::setSizePolicy ( const QSizePolicy & policy )

Sets the size policy to policy. The size policy describes how the item should grow horizontally and vertically when arranged in a layout.

QGraphicsLayoutItem's default size policy is (QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::DefaultType), but it is common for subclasses to change the default. For example, QGraphicsWidget defaults to (QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType).

See also sizePolicy() and QWidget::sizePolicy().

void QGraphicsLayoutItem::setSizePolicy ( QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType = QSizePolicy::DefaultType )

This is an overloaded member function, provided for convenience.

This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)).

See also sizePolicy() and QWidget::sizePolicy().

QSizeF QGraphicsLayoutItem::sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const   [pure virtual protected]

This pure virtual function returns the size hint for which of the QGraphicsLayoutItem, using the width or height of constraint to constrain the output.

Reimplement this function in a subclass of QGraphicsLayoutItem to provide the necessary size hints for your items.

See also effectiveSizeHint().

QSizePolicy QGraphicsLayoutItem::sizePolicy () const

Returns the current size policy.

See also setSizePolicy() and QWidget::sizePolicy().

void QGraphicsLayoutItem::updateGeometry ()   [virtual]

This virtual function discards any cached size hint information. You should always call this function if you change the return value of the sizeHint() function. Subclasses must always call the base implementation when reimplementing this function.

See also effectiveSizeHint().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

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 4.4
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