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  · 

QHeader Class Reference


The QHeader class provides a table header. More...

#include <qheader.h>

Inherits QWidget.

Inherited by QTableHeader.

List of all member functions.

Public Members

  • QHeader ( QWidget * parent=0, const char * name=0 ) 
  • QHeader ( int, QWidget * parent=0, const char * name=0 ) 
  • ~QHeader () 
  • int addLabel ( const QString &, int size = -1 ) 
  • int addLabel ( const QIconSet &, const QString &, int size = -1 ) 
  • void removeLabel ( int section ) 
  • virtual void setLabel ( int, const QString &, int size = -1 ) 
  • virtual void setLabel ( int, const QIconSet &, const QString &, int size = -1 ) 
  • QString label ( int section ) const
  • QIconSet* iconSet ( int section ) const
  • virtual void setOrientation ( Orientation ) 
  • Orientation orientation () const
  • virtual void setTracking ( bool enable ) 
  • bool tracking () const
  • virtual void setClickEnabled ( bool, int section = -1 ) 
  • virtual void setResizeEnabled ( bool, int section = -1 ) 
  • virtual void setMovingEnabled ( bool ) 
  • bool isClickEnabled ( int section = -1 ) const
  • bool isResizeEnabled ( int section = -1 ) const
  • bool isMovingEnabled () const
  • void resizeSection ( int section, int s ) 
  • int sectionSize ( int section ) const
  • int sectionPos ( int section ) const
  • int sectionAt ( int pos ) const
  • int count () const
  • virtual void setCellSize ( int, int ) (obsolete)
  • int cellSize ( int ) const (obsolete)
  • int cellPos ( int ) const (obsolete)
  • int cellAt ( int ) const (obsolete)
  • int offset () const
  • int mapToSection ( int index ) const
  • int mapToIndex ( int section ) const
  • int mapToLogical ( int ) const (obsolete)
  • int mapToActual ( int ) const (obsolete)
  • void moveSection ( int section, int toIndex ) 
  • virtual void moveCell ( int, int ) (obsolete)
  • void setSortIndicator ( int section, bool increasing = TRUE ) 

Public Slots

Signals

  • void clicked ( int section ) 
  • void pressed ( int section ) 
  • void released ( int section ) 
  • void sizeChange ( int section, int oldSize, int newSize ) 
  • void indexChange ( int section, int fromIndex, int toIndex ) 
  • void sectionClicked ( int ) (obsolete)
  • void moved ( int, int ) (obsolete)

Protected Members

  • QRect sRect ( int index ) 
  • void paintSection ( QPainter * p, int index, QRect fr ) 
  • void paintSectionLabel ( QPainter * p, int index, const QRect & fr ) 

Properties

TypeNameREADWRITEOptions
OrientationorientationorientationsetOrientation 
booltrackingtrackingsetTracking 
intcountcount  
intoffsetoffsetsetOffset 
boolmovingisMovingEnabledsetMovingEnabled 

Detailed Description

The QHeader class provides a table header.

This class provides a table header as known from spreadsheet-like widgets. QHeader can be used vertically or horizontally (see setOrientation()).

With addLabel() you can add sections, and with removeLabel() you can remove them. If you enabled clicking for one or all sections (see setClickEnabled()), the user can reorder the sections and click on them which may be used for sorting (see also setSortIndicator()). This feature is turned on by default.

So, if the user reorders the sections by clicking and moving them with the mouse the index of a section may change. This means, the section you inserted at the first position might be displayed at a different index then. To get the index at which e.g the first section is displayed, use mapToIndex() with 0 as argument for our example.

If you want e.g. to know which section is displayed at e.g. index 3 use mapToSection() with 3 as argument.

So, you can always work with the section numbers as you inserted them without caring about the index at which they are displayed at the moment. Also the API of QHeader works with the section numbers.

See also QListView and QTableView.


Member Function Documentation

QHeader::QHeader ( QWidget * parent=0, const char * name=0 )

Constructs a horizontal header.

The parent and name arguments are sent to the QWidget constructor.

QHeader::QHeader ( int n, QWidget * parent=0, const char * name=0 )

Constructs a horizontal header with n sections.

The parent and name arguments are sent to the QWidget constructor.

QHeader::~QHeader ()

Destructs the header.

int QHeader::addLabel ( const QIconSet & iconset, const QString & s, int size = -1 )

Adds a new section, with icon set iconset and label text s. Returns the index. If size is non-negative, the section width is set to size, otherwise a size currently sufficient for the label is used.

int QHeader::addLabel ( const QString & s, int size = -1 )

Adds a new section, with label text s. Returns the index. If size is non-negative, the section width is set to size, otherwise a size currently sufficient for the label text is used.

int QHeader::cellAt ( int pos ) const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use sectionAt() instead!

Returns the index at which the section is displayed, which contains pos in widget coordinates, or -1 if pos is outside the header sections.

int QHeader::cellPos ( int i ) const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use sectionPos() instead!

Returns the position in pixels of the section which is displayed at the index i. The position is measured from the start of the header.

int QHeader::cellSize ( int i ) const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use sectionSize() instead!

Returns the size in pixels of the section which is displayed at the index i.

void QHeader::clicked ( int section ) [signal]

This signal is emitted when the user clicked onto the section section.

See also pressed() and released().

int QHeader::count () const

Returns the number of sections in the header.

QIconSet * QHeader::iconSet ( int section ) const

Returns the icon set set on section section.

void QHeader::indexChange ( int section, int fromIndex, int toIndex ) [signal]

This signal is emitted if the user moved the section section, which was displayed at the index fromIndex to the new index toIndex.

bool QHeader::isClickEnabled ( int section = -1 ) const

Returns whether the section section is clickable or not. If section is out of range (negative or larger than count() - 1), TRUE is returned if all sections are clickable, else FALSE.

See also setClickEnabled().

bool QHeader::isMovingEnabled () const

Returns TRUE if the sections of the header can be moved around be the user, otherwise FALSE.

See also setMovingEnabled().

bool QHeader::isResizeEnabled ( int section = -1 ) const

Returns whether the section section is resizeable or not. If section is out of range (negative or larger than count() - 1), TRUE is returned if all sections are resizeable, else FALSE.

See also setResizeEnabled().

QString QHeader::label ( int section ) const

Returns the text set on section section.

int QHeader::mapToActual ( int l ) const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use mapToIndex() instead!

Translates from logical index l to actual index (index, at which the section l is displayed) . Returns -1 if l is outside the legal range.

See also mapToLogical().

int QHeader::mapToIndex ( int section ) const

Returns the index at which the section section is currently displayed.

int QHeader::mapToLogical ( int a ) const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use mapToSection() instead!

Translates from actual index a (index at which the section is displayed) to logical index of the section. Returns -1 if a is outside the legal range.

See also mapToActual().

int QHeader::mapToSection ( int index ) const

Returns the section which is displayed at the index index.

void QHeader::mouseMoveEvent ( QMouseEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QHeader::mousePressEvent ( QMouseEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QHeader::mouseReleaseEvent ( QMouseEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QHeader::moveCell ( int fromIdx, int toIdx ) [virtual]

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use moveSection() instead!

Moves the section which is currently displayed at the index fromIndex to the index toIdx.

void QHeader::moveSection ( int section, int toIndex )

Moves the section section to be displayed at the index toIndex.

void QHeader::moved ( int fromIndex, int toIndex ) [signal]

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use indexChange() instead!

This signal is emitted when the user has moved the section which is displayed at the index fromIndex to the index toIndex.

int QHeader::offset () const

Returns the leftmost (or uppermost for vertical headers) visible pixel.

Orientation QHeader::orientation () const

Returns Horizontal if the header is horizontal, Vertical if the header is vertical.

void QHeader::paintEvent ( QPaintEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QHeader::paintSection ( QPainter * p, int index, QRect fr ) [protected]

Paints actual section index of the header, inside rectangle fr in widget coordinates.

Calls paintSectionLabel().

void QHeader::paintSectionLabel ( QPainter * p, int index, const QRect & fr ) [protected]

Paints the label of actual section index of the header, inside rectangle fr in widget coordinates.

Called by paintSection().

void QHeader::pressed ( int section ) [signal]

This signal is emitted when the user presses section section down.

See also released().

void QHeader::released ( int section ) [signal]

This signal is emitted when section section is released.

See also pressed().

void QHeader::removeLabel ( int section )

Removes the section section.

void QHeader::resizeSection ( int section, int s )

Resizes the section section to s pixels.

QRect QHeader::sRect ( int index ) [protected]

Returns the rectangle covered by index index.

int QHeader::sectionAt ( int pos ) const

Returns the section which contains the position pos given in pixels.

See also offset().

void QHeader::sectionClicked ( int index ) [signal]

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use clicked() instead!

This signal is emitted when a part of the header is clicked. index is the index at which the section is displayed.

In a list view, this signal would typically be connected to a slot which sorts the specified column (or row).

int QHeader::sectionPos ( int section ) const

Returns the position (in pixels) at which the section starts.

See also offset().

int QHeader::sectionSize ( int section ) const

Returns the size of the section in pixels.

void QHeader::setCellSize ( int section, int s ) [virtual]

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use resizeSection() instead!

Sets the size of the section section to s pixels.

Warning: does not repaint or send out signals.

void QHeader::setClickEnabled ( bool enable, int section = -1 ) [virtual]

Enable clicking in section section if enable is TRUE, disable otherwise. If section is negative (as it is by default), clicking is enabled/disabled for all current and new sections.

If enabled, the clicked() signal is emitted when the user clicks.

See also setMovingEnabled() and setResizeEnabled().

void QHeader::setLabel ( int section, const QIconSet & iconset, const QString & s, int size = -1 ) [virtual]

Sets the icon on the section section to iconset and the text to s. If the section does not exist, nothing happens. If size is non-negative, the section width is set to size.

Any icon set that has been defined for this section remains unchanged.

void QHeader::setLabel ( int section, const QString & s, int size = -1 ) [virtual]

Sets the text on section section to s. If the section does not exist, nothing happens. If size is non-negative, the section width is set to size.

Any icon set that has been defined for this section remains unchanged.

void QHeader::setMovingEnabled ( bool enable ) [virtual]

Enable the user to exchange sections if enable is TRUE, disable otherwise.

If you enable moving here, the indexChange() signal is emitted if the user moves a section.

See also setClickEnabled() and setResizeEnabled().

void QHeader::setOffset ( int x ) [virtual slot]

Scrolls the header such that x becomes the leftmost (or uppermost for vertical headers) visible pixel.

void QHeader::setOrientation ( Orientation orientation ) [virtual]

Sets the header orientation. The orientation must be QHeader::Vertical or QHeader::Horizontal.

When adding labels without the size parameter, setOrientation should be called first, otherwise labels will be sized incorrectly.

See also orientation().

void QHeader::setResizeEnabled ( bool enable, int section = -1 ) [virtual]

Enable user resizing of the section section if enable is TRUE, disable otherwise. If section is negative (as it is by default), resizing is enabled/disabled for all current and new sections.

If the user resizes a section (because this feature enabled it), a sizeChange() signal is emitted.

See also setMovingEnabled() and setClickEnabled().

void QHeader::setSortIndicator ( int section, bool increasing = TRUE )

As often the QHeader is used together with a list widget, QHeader can indicate a sort order. This is done using an arrow at the right edge of a section which points up or down. section specifies in which section this arrow should be drawn, and increasing, if the arrow should point to the bottom (TRUE) or the the top (FALSE). If section is -1, no arrow is drawn.

See also QListView::setShowSortIndicator().

void QHeader::setTracking ( bool enable ) [virtual]

Sets tracking if enable is TRUE, otherwise turns off tracking. If tracking is on, the sizeChange() signal is emitted continuously while the mouse is moved, otherwise it is only emitted when the mouse button is released.

See also tracking().

void QHeader::setUpdatesEnabled ( bool enable ) [virtual slot]

reimp.

Reimplemented from QWidget.

void QHeader::showEvent ( QShowEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QHeader::sizeChange ( int section, int oldSize, int newSize ) [signal]

This signal is emitted when the user has changed the size of some of a section of the header from oldSize to newSize. This signal is typically connected to a slot that repaints the table.

QSize QHeader::sizeHint () const [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

QSizePolicy QHeader::sizePolicy () const [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

bool QHeader::tracking () const

Returns TRUE if tracking is on, FALSE otherwise.

See also setTracking().


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 85
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. 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
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 19
  7. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

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