# QHeader Class Reference

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

`#include <qheader.h>`

Inherits QTableView.

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 char *, int size = -1 )
- void setLabel ( int, const char *, int size = -1 )
- const char* label ( int )
- void setOrientation ( Orientation )
- Orientation orientation () const
- void setTracking ( bool enable )
- bool tracking () const
- void setClickEnabled ( bool, int logIdx = -1 )
- void setResizeEnabled ( bool, int logIdx = -1 )
- void setMovingEnabled ( bool )
- void setCellSize ( int i, int s )
- int cellSize ( int i ) const
- int cellPos ( int i ) const
- int cellAt ( int i ) const
- int count () const
- int offset () const
- virtual QSize sizeHint () const
- int mapToLogical ( int ) const
- int mapToActual ( int ) const

## Public Slots

- void setOffset ( int )

## Signals

- void sectionClicked ( int )
- void sizeChange ( int section, int oldSize, int newSize )
- void moved ( int from, int to )

## Protected Members

- virtual void resizeEvent ( QResizeEvent * )
- QRect sRect ( int i )
- virtual void paintCell ( QPainter *, int, int )
- virtual void setupPainter ( QPainter * )
- virtual int cellHeight ( int )
- virtual int cellWidth ( int )
- virtual void mousePressEvent ( QMouseEvent * )
- virtual void mouseReleaseEvent ( QMouseEvent * )
- virtual void mouseMoveEvent ( QMouseEvent * )

## Detailed Description

The QHeader class provides a table header.

This is a table heading of the type used in a list view. It gives the user the opportunity to resize and move the columns (or rows for vertical headings).

This class can be used without a table view, if you need to control table-like structures.

See also: QListView, QTableView and Microsoft Style Guide

## 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 char * 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 c ) const

Returns the actual index of the section at position c, or -1 if outside.

### int QHeader::cellHeight ( int row ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QTableView.

### int QHeader::cellPos ( int i ) const

Returns the position in pixels of section i of the header. i is the actual index.

### int QHeader::cellSize ( int i ) const

Returns the size in pixels of section i of the header. i is the actual index.

### int QHeader::cellWidth ( int col ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QTableView.

### int QHeader::count () const

Returns the number of sections in the header.

### const char* QHeader::label ( int i )

Returns the text set on logical section i.

### int QHeader::mapToActual ( int l ) const

Translates from logical index l to actual index. Returns -1 if l is outside the legal range.

### int QHeader::mapToLogical ( int a ) const

Translates from actual index a to logical index. Returns -1 if a is outside the legal range.

### void QHeader::moved ( int from, int to ) `[signal]`

This signal is emitted when the user has moved column from to position to.

### int QHeader::offset () const

int QHeader::offset() const Returns the leftmost (or uppermost for vertical headers) visible pixel.

### QHeader::Orientation QHeader::orientation() const

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

### void QHeader::paintCell ( QPainter * p, int row, int col ) `[virtual protected]`

paints a section of the header.

Reimplemented from QTableView.

### void QHeader::resizeEvent ( QResizeEvent * ) `[virtual protected]`

Handles resize events.

Reimplemented from QWidget.

### QRect QHeader::sRect ( int i ) `[protected]`

Returns the rectangle covered by actual section i.

### void QHeader::sectionClicked ( int logical ) `[signal]`

This signal is emitted when a part of the header is clicked. In a list view, this signal would typically be connected to a slot which sorts the specified column.

### void QHeader::setCellSize ( int i, int s )

Sets the size of logical cell i to s pixels.

Warning: does not repaint or send out signals at present.

### void QHeader::setClickEnabled ( bool enable, int i = -1 )

Enable clicking in column i if enable is TRUE, disable otherwise. If i is negative, clicking is enabled/disabled for all columns.

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

See also: setMovingEnabled() and setResizeEnabled().

### void QHeader::setLabel ( int i, const char * s, int size = -1 )

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

### void QHeader::setMovingEnabled ( bool enable )

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

See also: setClickEnabled() and setResizeEnabled().

### void QHeader::setOffset ( int x ) `[slot]`

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

### void QHeader::setOrientation ( Orientation orientation )

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 i = -1 )

Enable user resizing of column i if enable is TRUE, disable otherwise. If i is negative, resizing is enabled/disabled for all columns.

See also: setMovingEnabled() and setClickEnabled().

### void QHeader::setTracking ( bool enable )

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::setupPainter ( QPainter * p ) `[virtual protected]`

sets up the painter.

Reimplemented from QTableView.

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

This signal is emitted when the user has changed the size of some of the parts of the header. This signal is typically connected to a slot that repaints the table. section is the logical section resized.

### QSize QHeader::sizeHint () const `[virtual]`

Returns the recommended size of the QHeader.

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.troll.no):

This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.

It was generated from the following files:

- qheader.h: 1998/08/21
- qheader.cpp: 1998/10/30