Classes - Annotated - Tree - Functions - Home - Structure

QHeader Class Reference

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

#include <qheader.h>

Inherits QWidget.

List of all member functions.

Public Members

Public Slots

Signals

Properties

Protected Members


Detailed Description

The QHeader class provides a table header.

This class provides a table header as used in many spreadsheets. 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 that the section you inserted at the first position might then be displayed at a different index. 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 to know which section is displayed at index 3, for example, use mapToSection(3).

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. The API of QHeader also 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 ()

Destroys the header.

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::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.

void QHeader::adjustHeaderSize ()

Adjusts the header size to fit as good as possible, if isStretchEnabled() is TRUE.

int QHeader::cellAt ( int pos ) const

This function is obsolete. It is provided to keep old source working. 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. We strongly advise against using it in new code.

Use sectionPos() instead!

Returns the position in pixels of the section that 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. We strongly advise against using it in new code.

Use sectionSize() instead!

Returns the size in pixels of the section that 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. See the "count" property for details.

int QHeader::headerWidth () const

returns the total width of all Header columns.

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, otherwise FALSE.

See also setClickEnabled().

bool QHeader::isMovingEnabled () const

Returns TRUE whether the header sections can be moved, otherwise returns FALSE. See the "moving" property for details.

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, otherwise FALSE.

See also setResizeEnabled().

bool QHeader::isStretchEnabled () const

Returns TRUE whether the header sections always cover the full width (or height) of the header or not, otherwise returns FALSE. See the "stretching" property for details.

bool QHeader::isStretchEnabled ( int section ) const

Returns whether the header sections always cover the full width of the header by automatically adjusting the section section.

See also stretching.

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. 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. 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 that is displayed at the index index.

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

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Use moveSection() instead!

Moves the section that is currently displayed at index fromIdx to 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. 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 header's leftmost (or uppermost) visible pixel. See the "offset" property for details.

Orientation QHeader::orientation () const

Returns the header's physical orientation. See the "orientation" property for details.

void QHeader::paintSection ( QPainter * p, int index, const QRect & fr ) [virtual 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 ) [virtual 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 index 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. 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 that 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.

QRect QHeader::sectionRect ( int section ) const

Returns the rectangle covered by section section.

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. 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 moving and setResizeEnabled().

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.

Example: table/small-table-demo/main.cpp.

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::setMovingEnabled ( bool ) [virtual]

Sets whether the header sections can be moved. See the "moving" property for details.

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

Sets the header's leftmost (or uppermost) visible pixel to pos. See the "offset" property for details.

void QHeader::setOrientation ( Orientation ) [virtual]

Sets the header's physical orientation. See the "orientation" property for details.

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 moving and setClickEnabled().

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

Because the QHeader is often 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 showSortIndicator.

void QHeader::setStretchEnabled ( bool b )

Sets whether the header sections always cover the full width (or height) of the header or not to b. See the "stretching" property for details.

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

Sets whether the sizeChange() signal is emitted continuously or not to enable. See the "tracking" property for details.

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.

bool QHeader::tracking () const

Returns TRUE whether the sizeChange() signal is emitted continuously or not, otherwise returns FALSE. See the "tracking" property for details.


Property Documentation

int count

This property holds the number of sections in the header.

Get this property's value with count().

bool moving

This property holds whether the header sections can be moved.

If you set this property to TRUE, the indexChange() signal is emitted if the user moves a section.

Set this property's value with setMovingEnabled() and get this property's value with isMovingEnabled().

See also setClickEnabled() and setResizeEnabled().

int offset

This property holds the header's leftmost (or uppermost) visible pixel.

Setting this property will scroll the header so that offset becomes the leftmost (or uppermost for vertical headers) visible pixel.

Set this property's value with setOffset() and get this property's value with offset().

Orientation orientation

This property holds the header's physical orientation.

The orientation can be either QHeader::Vertical or QHeader::Horizontal.

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

Set this property's value with setOrientation() and get this property's value with orientation().

bool stretching

This property holds whether the header sections always cover the full width (or height) of the header or not.

If you set this property to TRUE, the section section of the header will adjust itself when resized, so that the sections always cover the full width (or height, if it is a vertical header) of the header. If section is -1, all sections are adjusted equally.

Set this property's value with setStretchEnabled() and get this property's value with isStretchEnabled().

See also adjustHeaderSize().

bool tracking

This property holds whether the sizeChange() signal is emitted continuously or not.

If tracking is on, the sizeChange() signal is emitted continuously while the mouse is moved (when the header is resized), otherwise it is only emitted when the mouse button is released.

Set this property's value with setTracking() and get this property's value with tracking().


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


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


Copyright © 2000 TrolltechTrademarks
Qt version main-beta1