Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QHeaderView Class Reference

The QHeaderView class provides a header row or header column for item views. More...

    #include <QHeaderView>

Inherits QAbstractItemView.

- List of all members, including inherited members

### Public Types

- enum ResizeMode { Interactive, Stretch, Custom }

### Writable Properties

- highlightCurrentSection : bool
- showSortIndicator : bool

- 7 writable properties inherited from QAbstractItemView
- 2 writable properties inherited from QViewport
- 5 writable properties inherited from QFrame
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- 1 read-only property inherited from QViewport
- 1 read-only property inherited from QFrame
- 24 read-only properties inherited from QWidget

### Public Functions

- QHeaderView ( Qt::Orientation orientation, QWidget * parent = 0 )
- virtual ~QHeaderView ()
- int count () const
- virtual void doItemsLayout ()
- void hideSection ( int section )
- int index ( int section ) const
- int indexAt ( int position ) const
- bool isClickable () const
- bool isMovable () const
- bool isSectionHidden ( int section ) const
- int length () const
- void moveSection ( int from, int to )
- int offset () const
- Qt::Orientation orientation () const
- ResizeMode resizeMode ( int section ) const
- void resizeSection ( int section, int size )
- int section ( int index ) const
- int sectionAt ( int position ) const
- int sectionAt ( int x, int y ) const
- int sectionAt ( const QPoint & pos ) const
- int sectionPosition ( int section ) const
- int sectionSize ( int section ) const
- int sectionSizeHint ( int section ) const
- void setClickable ( bool clickable )
- void setMovable ( bool movable )
- void setResizeMode ( ResizeMode mode )
- void setResizeMode ( ResizeMode mode, int section )
- void setSectionHidden ( int section, bool hide )
- void setSortIndicator ( int section, Qt::SortOrder order )
- void showSection ( int section )
- virtual QSize sizeHint () const
- Qt::SortOrder sortIndicatorOrder () const
- int sortIndicatorSection () const

- 22 public functions inherited from QAbstractItemView
- 4 public functions inherited from QViewport
- 2 public functions inherited from QFrame
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- void headerDataChanged ( Qt::Orientation orientation, int first, int last )
- void setOffset ( int offset )

- 6 public slots inherited from QAbstractItemView
- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void sectionAutoResize ( int section, ResizeMode mode )
- void sectionClicked ( int section, Qt::ButtonState state )
- void sectionCountChanged ( int oldCount, int newCount )
- void sectionHandleDoubleClicked ( int section, Qt::ButtonState state )
- void sectionIndexChanged ( int section, int oldIndex, int newIndex )
- void sectionPressed ( int section, Qt::ButtonState state )
- void sectionSizeChanged ( int section, int oldSize, int newSize )

- 9 signals inherited from QAbstractItemView
- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- virtual int horizontalOffset () const
- virtual void paintSection ( QPainter * painter, const QRect & rect, int section ) const
- virtual QSize sectionSizeFromContents ( int section ) const
- virtual int verticalOffset () const

- 33 protected functions inherited from QAbstractItemView
- 17 protected functions inherited from QViewport
- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

### Protected Slots

- void sectionsInserted ( const QModelIndex & parent, int first, int last )
- void sectionsRemoved ( const QModelIndex & parent, int first, int last )

- 8 protected slots inherited from QAbstractItemView

## Detailed Description

The QHeaderView class provides a header row or header column for item views.

A QHeaderView displays the headers used in item views such as the QTableView and QTreeView classes. It takes the place of the `QHeader` class previously used for the same purpose, but uses the Qt's model/view architecture for consistency with the item view classes.

Each header has an orientation() and a number of sections, given by the count() function. Sections can be moved and resized using moveSection() and resizeSection(); they can be hidden and shown with hideSection() and showSection().

Each section of a header is described by a section ID, specified by its section(), and can be located at a particular index() in the header. A section can have a sort indicator set with setSortIndicator(); this indicates whether the items in the associated item view will be sorted in the order given by the section.

A header can be fixed in place, or made movable with setMovable(). It can be made clickable with setClickable(), and has resizing behavior in accordance with setResizeMode().

A header emits sectionIndexChanged() if the user moves a section, sectionSizeChanged() if the user resizes a section, and sectionClicked() and sectionHandleDoubleClicked() in response to mouse clicks. A header also emits sectionCountChanged() and sectionAutoResize().

You can identify a section using the section() and sectionAt() functions, or by its index position, using the index() and indexAt() functions. Note that the index can change if a section is moved.

For a horizontal header the section is equivalent to a column in the model, and for a vertical header the section is equivalent to a row in the model.

See also Model/View Programming, QListView, QTableView, QTreeView, and QHeaderWidget.

## Member Type Documentation

### enum QHeaderView::ResizeMode

`QHeaderView::Interactive` | Don't automatically change the size (let the user do it manually).
`QHeaderView::Stretch` | Fill all the available visible space.
`QHeaderView::Custom` | Don't automatically change the size here, leave it to some other object.

## Property Documentation

### highlightCurrentSection : bool

This property holds whether the current selection is highlighted.

Access functions:

- bool highlightCurrentSection () const
- void setHighlightCurrentSection ( bool highlight )

### showSortIndicator : bool

This property holds whether the sort indicator is shown.

Access functions:

- bool isSortIndicatorShown () const
- void setSortIndicatorShown ( bool show )

## Member Function Documentation

### QHeaderView::QHeaderView ( Qt::Orientation orientation, QWidget * parent = 0 )

Creates a new generic header with the given orientation and parent.

### QHeaderView::~QHeaderView () `[virtual]`

Destroys the header.

### int QHeaderView::count () const

Returns the number of sections in the header.

### void QHeaderView::doItemsLayout () `[virtual]`

### void QHeaderView::headerDataChanged ( Qt::Orientation orientation, int first, int last ) `[slot]`

Updates the changed header sections

### void QHeaderView::hideSection ( int section )

Hides the specified section.

See also showSection().

### int QHeaderView::horizontalOffset () const `[virtual protected]`

Returns the horizontal offset of the header. This is 0 for vertical headers.

Reimplemented from QAbstractItemView.

See also offset().

### int QHeaderView::index ( int section ) const

Returns the index position of the given section.

See also section().

### int QHeaderView::indexAt ( int position ) const

Returns the index of the section that covers the given position.

### bool QHeaderView::isClickable () const

Returns true if the header is clickable; otherwise returns false. A clickable header could be set up to allow the user to change the representation of the data in the view related to the header.

See also setClickable().

### bool QHeaderView::isMovable () const

Returns true if the header can be moved by the user; otherwise returns false.

See also setMovable().

### bool QHeaderView::isSectionHidden ( int section ) const

Returns true if the section is hidden from the user; otherwise returns false.

### int QHeaderView::length () const

Returns the length along the orientation of the header.

See also sizeHint().

### void QHeaderView::moveSection ( int from, int to )

Moves the section at index position from to occupy index position to.

### int QHeaderView::offset () const

Returns the offset of the header: this is the header's left-most (or top-most for vertical headers) visible pixel.

See also setOffset().

### Qt::Orientation QHeaderView::orientation () const

Returns the orientation of the header.

See also Qt::Orientation.

### void QHeaderView::paintSection ( QPainter * painter, const QRect & rect, int section ) const `[virtual protected]`

Paints the section using the given painter with the option and model index.

You normally would not need to use this function.

### ResizeMode QHeaderView::resizeMode ( int section ) const

Returns the resize mode that applies to the given section.

### void QHeaderView::resizeSection ( int section, int size )

Resizes the given section to the given size.

### int QHeaderView::section ( int index ) const

Returns the number of the section at the given index position.

See also index().

### int QHeaderView::sectionAt ( int position ) const

Returns the section that covers the given position.

### int QHeaderView::sectionAt ( int x, int y ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the section at the given coordinate. If the header is horizontal x will be used, otherwise y will be used to find the section.

### int QHeaderView::sectionAt ( const QPoint & pos ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the section at the position given in pos. If the header is horizontal x will be used, otherwise y will be used to find the section.

### void QHeaderView::sectionAutoResize ( int section, ResizeMode mode ) `[signal]`

This signal is emitted when a section is automatically resized. The section's number is specified by section, and the resize mode by mode.

### void QHeaderView::sectionClicked ( int section, Qt::ButtonState state ) `[signal]`

This signal is emitted when a section is clicked. The section's number is specified by section, and the button by state.

### void QHeaderView::sectionCountChanged ( int oldCount, int newCount ) `[signal]`

This signal is emitted when the number of sections changes; i.e. when sections are added or deleted. The original count is specified by oldCount, and the new count by newCount.

### void QHeaderView::sectionHandleDoubleClicked ( int section, Qt::ButtonState state ) `[signal]`

This signal is emitted when a section is double-clicked. The section's number is specified by section, and the button by state.

### void QHeaderView::sectionIndexChanged ( int section, int oldIndex, int newIndex ) `[signal]`

This signal is emitted when a section is moved. The section's number is specified by section, the old index position by oldIndex, and the new index position by newIndex.

### int QHeaderView::sectionPosition ( int section ) const

Returns the index position of the given section.

### void QHeaderView::sectionPressed ( int section, Qt::ButtonState state ) `[signal]`

This signal is emitted when a section is pressed. The section's number is specified by section, and the button by state.

### int QHeaderView::sectionSize ( int section ) const

Returns the width (or height for vertical headers) of the given section.

### void QHeaderView::sectionSizeChanged ( int section, int oldSize, int newSize ) `[signal]`

This signal is emitted when a section is resized. The section's number is specified by section, the old size by oldSize, and the new size by newSize.

### QSize QHeaderView::sectionSizeFromContents ( int section ) const `[virtual protected]`

Returns the size of the contents of the give section.

### int QHeaderView::sectionSizeHint ( int section ) const

Returns a suitable size hint for the given section.

See also sizeHint().

### void QHeaderView::sectionsInserted ( const QModelIndex & parent, int first, int last ) `[protected slot]`

This slot is called when sections are inserted into the parent, first and last signify where the new sections are inserted. (first and last will be the same if just one section is inserted.)

### void QHeaderView::sectionsRemoved ( const QModelIndex & parent, int first, int last ) `[protected slot]`

This slot is called when sections are removed from the parent, first and last signify where the sections are removed from. (first and last will be the same if just one section is removed.)

### void QHeaderView::setClickable ( bool clickable )

If clickable is true, the header will respond to single clicks.

See also isClickable().

### void QHeaderView::setMovable ( bool movable )

If movable is true, the header may be moved by the user; otherwise it is fixed in place.

See also isMovable().

### void QHeaderView::setOffset ( int offset ) `[slot]`

Sets the header's offset to offset.

See also offset().

### void QHeaderView::setResizeMode ( ResizeMode mode )

Sets the constraints on how the header can be resized to those described by the given mode.

See also QLayout::ResizeMode.

### void QHeaderView::setResizeMode ( ResizeMode mode, int section )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the constraints on how the section in the header can be resized to those described by the given mode.

See also QLayout::ResizeMode.

### void QHeaderView::setSectionHidden ( int section, bool hide )

If hide is true the section is hidden, otherwise the section is shown.

### void QHeaderView::setSortIndicator ( int section, Qt::SortOrder order )

Sets the sort indicator for the given section in the direction specified by order, and removes the sort indicator from any other section that was showing it.

See also sortIndicatorSection() and sortIndicatorOrder().

### void QHeaderView::showSection ( int section )

Shows the specified section.

See also hideSection().

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

Returns a suitable size hint for this header.

Reimplemented from QWidget.

See also sectionSizeHint().

### Qt::SortOrder QHeaderView::sortIndicatorOrder () const

Returns the order for the sort indicator. If no section has a sort indicator the return value of this function is undefined.

See also setSortIndicator() and sortIndicatorSection().

### int QHeaderView::sortIndicatorSection () const

Returns the number of the section that has a sort indicator, or -1 if no section has a sort indicator.

See also setSortIndicator() and sortIndicatorOrder().

### int QHeaderView::verticalOffset () const `[virtual protected]`

Returns the vertical offset of the header. This is 0 for horizontal headers.

Reimplemented from QAbstractItemView.

See also offset().