Customized LayoutmanagerThis examples demonstrates how to write a customized layout (geometry) manager, like a Card-Layout, Border-Layout and Flow-Layout. See also: Documentation of Geometry Management. Header file of the Flow-Layout: /**************************************************************************** ** $Id: //depot/qt/main/examples/customlayout/flow.h#5 $ ** ** Definition of simple flow layout for custom layout example ** ** Created : 979899 ** ** Copyright (C) 1997 by Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #ifndef FLOW_H #define FLOW_H #include <qlayout.h> #include <qlist.h> class SimpleFlow : public QLayout { public: SimpleFlow( QWidget *parent, int border=0, int space=-1, const char *name=0 ) : QLayout( parent, border, space, name ), cached_width(0) {} SimpleFlow( QLayout* parent, int space=-1, const char *name=0 ) : QLayout( parent, space, name ), cached_width(0) {} SimpleFlow( int space=-1, const char *name=0 ) : QLayout( space, name ), cached_width(0) {} ~SimpleFlow(); void addItem( QLayoutItem *item); bool hasHeightForWidth() const; int heightForWidth( int ) const; QSize sizeHint() const; QSize minimumSize() const; QLayoutIterator iterator(); QSizePolicy::ExpandData expanding() const; protected: void setGeometry( const QRect& ); private: int doLayout( const QRect&, bool testonly = FALSE ); QList<QLayoutItem> list; int cached_width; int cached_hfw; }; #endif Implementation of the Flow-Layout: /**************************************************************************** ** $Id: //depot/qt/main/examples/customlayout/flow.cpp#4 $ ** ** Implementing your own layout: flow example ** ** Copyright (C) 1996 by Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "flow.h" class SimpleFlowIterator :public QGLayoutIterator { public: SimpleFlowIterator( QList<QLayoutItem> *l ) :idx(0), list(l) {} uint count() const; QLayoutItem *current(); QLayoutItem *next(); QLayoutItem *takeCurrent(); private: int idx; QList<QLayoutItem> *list; }; uint Header file of the Border-Layout: /**************************************************************************** ** $Id: //depot/qt/main/examples/customlayout/border.h#5 $ ** ** Definition of simple flow layout for custom layout example ** ** Created : 979899 ** ** Copyright (C) 1997 by Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #ifndef BORDER_H #define BORDER_H #include <qlayout.h> #include <qlist.h> class BorderWidgetItem : public QWidgetItem { public: BorderWidgetItem( QWidget *w ) : QWidgetItem( w ) {} void setGeometry( const QRect &r ) { widget()->setGeometry( r ); } }; class BorderLayout : public QLayout { public: enum Position { West = 0, North, South, East, Center }; struct BorderLayoutStruct { BorderLayoutStruct( QLayoutItem *i, Position p ) { item = i; pos = p; } QLayoutItem *item; Position pos; }; enum SizeType { Minimum = 0, SizeHint }; BorderLayout( QWidget *parent, int border = 0, int autoBorder = -1, const char *name = 0 ) : QLayout( parent, border, autoBorder, name ), cached( 0, 0 ), mcached( 0, 0 ), sizeDirty( TRUE ), msizeDirty( TRUE ) {} BorderLayout( QLayout* parent, int autoBorder = -1, const char *name = 0 ) : QLayout( parent, autoBorder, name ), cached( 0, 0 ), mcached( 0, 0 ), sizeDirty( TRUE ), msizeDirty( TRUE ) {} BorderLayout( int autoBorder = -1, const char *name = 0 ) : QLayout( autoBorder, name ), cached( 0, 0 ), mcached( 0, 0 ), sizeDirty( TRUE ), msizeDirty( TRUE ) {} ~BorderLayout(); void addItem( QLayoutItem *item ); void addWidget( QWidget *widget, Position pos ); void add( QLayoutItem *item, Position pos ); bool hasHeightForWidth() const; QSize sizeHint() const; QSize minimumSize() const; QLayoutIterator iterator(); QSizePolicy::ExpandData expanding() const; protected: void setGeometry( const QRect &rect ); private: void doLayout( const QRect &rect, bool testonly = FALSE ); void calcSize( SizeType st ); QList<BorderLayoutStruct> list; QSize cached, mcached; bool sizeDirty, msizeDirty; }; #endif Implementation of the Border-Layout: /**************************************************************************** ** $Id: //depot/qt/main/examples/customlayout/border.cpp#6 $ ** ** Implementing your own layout: flow example ** ** Copyright (C) 1996 by Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "border.h" class BorderLayoutIterator : public QGLayoutIterator { public: BorderLayoutIterator( const QList<BorderLayout::BorderLayoutStruct> *l ) : idx( 0 ) , list( (QList<BorderLayout::BorderLayoutStruct>*)l ) {} uint count() const; QLayoutItem *current(); BorderLayout::BorderLayoutStruct *currentStruct(); void toFirst(); QLayoutItem *next(); QLayoutItem *takeCurrent(); BorderLayoutIterator &operator++(); private: int idx; QList<BorderLayout::BorderLayoutStruct> *list; }; uint Header file of the Card-Layout: /**************************************************************************** ** $Id: //depot/qt/main/examples/customlayout/card.h#1 $ ** ** Definition of simple flow layout for custom layout example ** ** Created : 979899 ** ** Copyright (C) 1997 by Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #ifndef CARD_H #define CARD_H #include <qlayout.h> #include <qlist.h> class CardLayout : public QLayout { public: CardLayout( QWidget *parent, int dist ) : QLayout( parent, 0, dist ) {} CardLayout( QLayout* parent, int dist) : QLayout( parent, dist ) {} CardLayout( int dist ) : QLayout( dist ) {} ~CardLayout(); void addItem( QLayoutItem *item ); QSize sizeHint() const; QSize minimumSize() const; QLayoutIterator iterator(); void setGeometry( const QRect &rect ); private: QList<QLayoutItem> list; }; #endif Implementation of the Card-Layout: /**************************************************************************** ** $Id: //depot/qt/main/examples/customlayout/card.cpp#3 $ ** ** Implementing your own layout: flow example ** ** Copyright (C) 1996 by Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "card.h" class CardLayoutIterator :public QGLayoutIterator { public: CardLayoutIterator( QList<QLayoutItem> *l ) : idx( 0 ), list( l ) {} QLayoutItem *current(); QLayoutItem *next(); QLayoutItem *takeCurrent(); private: int idx; QList<QLayoutItem> *list; }; QLayoutItem * Main: /**************************************************************************** ** $Id: //depot/qt/main/examples/customlayout/main.cpp#2 $ ** ** Main for custom layout example ** ** Copyright (C) 1996 by Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "flow.h" #include "border.h" #include "card.h" #include < |
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le blog Digia au hasardCréer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut CuvelierLe blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.
CommunautéRessources
Liens utilesContact
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 ! |
Copyright © 2000-2012 - www.developpez.com