The QHeader class provides a header row or column, e.g. for tables and listviews.
.PP
This class provides a header, e.g. a vertical header to display row labels, or a horizontal header to display column labels. It is used by QTable and QListView for example.
.PP
A header is composed of one or more \fIsections\fR, each of which can display a text label and an iconset. A sort indicator (an arrow) can also be displayed using setSortIndicator().
.PP
Sections are added with addLabel() and removed with removeLabel(). The label and iconset are set in addLabel() and can be changed later with setLabel(). Use count() to retrieve the number of sections in the header.
.PP
The orientation of the header is set with setOrientation(). If setStretchEnabled() is TRUE, the sections will expand to take up the full width (height for vertical headers) of the header. The user can resize the sections manually if setResizeEnabled() is TRUE. Call adjustHeaderSize() to have the sections resize to occupy the full width (or height).
.PP
A section can be moved with moveSection(). If setMovingEnabled() is TRUE (the default)the user may drag a section from one position to another. If a section is moved, the index positions at which sections were added (with addLabel()), may not be the same after the move. You don't have to worry about this in practice because the QHeader API works in terms of section numbers, so it doesn't matter where a particular section has been moved to.
.PP
If you want the current index position of a section call mapToIndex() giving it the section number. (This is the number returned by the addLabel() call which created the section.) If you want to get the section number of a section at a particular index position call mapToSection() giving it the index number.
.PP
Here's an example to clarify mapToSection() and mapToIndex():
.PP
<center>.nf
.TS
l - l. Index positions 0 1 2 3 Original section ordering Sect 0 Sect 1 Sect 2 Sect 3 Ordering after the user moves a section Sect 0 Sect 2 Sect 3
.TE
.fi
</center>
.PP
<center>.nf
.TS
l - l. \fIk\fR mapToSection(\fIk\fR) mapToIndex(\fIk\fR) 0 0 0 1 2 3 2 3 1 3 1
.TE
.fi
</center>
.PP
In the example above, if we wanted to find out which section is at index position 3 we'd call mapToSection(3) and get a section number of 1 since section 1 was moved. Similarly, if we wanted to know which index position section 2 occupied we'd call mapToIndex(2) and get an index of 1.
.PP
QHeader provides the clicked(), pressed() and released() signals. If the user changes the size of a section, the sizeChange() signal is emitted. If you want to have a sizeChange() signal emitted continuously whilst the user is resizing (rather than just after the resizing is finished), use setTracking(). If the user moves a section the indexChange() signal is emitted.
Adds a new section with label text \fIs\fR. Returns the index position where the section was added (at the right for horizontal headers, at the bottom for vertical headers). The section's width is set to \fIsize\fR. If \fIsize\fR < 0, an appropriate size for the text \fIs\fR is chosen.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Adds a new section with iconset \fIiconset\fR and label text \fIs\fR. Returns the index position where the section was added (at the right for horizontal headers, at the bottom for vertical headers). The section's width is set to \fIsize\fR, unless size is negative in which case the size is calculated taking account of the size of the text.
.SH "void QHeader::adjustHeaderSize ()"
Adjusts the size of the sections to fit the size of the header as completely as possible. Only sections for which isStretchEnabled() is TRUE will be resized.
.SH "int QHeader::cellAt ( int pos ) const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use sectionAt() instead.
.PP
Returns the index at which the section is displayed, which contains \fIpos\fR in widget coordinates, or -1 if \fIpos\fR is outside the header sections.
.SH "int QHeader::cellPos ( int i ) const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use sectionPos() instead.
.PP
Returns the position in pixels of the section that is displayed at the index \fIi\fR. The position is measured from the start of the header.
.SH "int QHeader::cellSize ( int i ) const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use sectionSize() instead.
.PP
Returns the size in pixels of the section that is displayed at the index \fIi\fR.
.SH "void QHeader::clicked ( int section )\fC [signal]\fR"
If isClickEnabled() is TRUE, this signal is emitted when the user clicks section \fIsection\fR.
.PP
See also pressed() and released().
.SH "int QHeader::count () const"
Returns the number of sections in the header. See the "count" property for details.
.SH "int QHeader::headerWidth () const"
Returns the total width of all the header columns.
.SH "QIconSet * QHeader::iconSet ( int section ) const"
Returns the icon set for section \fIsection\fR. If the section does not exist, 0 is returned.
.SH "void QHeader::indexChange ( int section, int fromIndex, int toIndex )\fC [signal]\fR"
This signal is emitted when the user moves section \fIsection\fR from index position \fIfromIndex\fR, to index position \fItoIndex\fR.
.SH "bool QHeader::isClickEnabled ( int section = -1 ) const"
Returns TRUE if section \fIsection\fR is clickable; otherwise returns FALSE.
.PP
If \fIsection\fR is out of range (negative or larger than count() - 1): returns TRUE if all sections are clickable; otherwise returns FALSE.
.PP
See also setClickEnabled().
.SH "bool QHeader::isMovingEnabled () const"
Returns TRUE if the header sections can be moved; otherwise returns FALSE. See the "moving" property for details.
.SH "bool QHeader::isResizeEnabled ( int section = -1 ) const"
Returns TRUE if section \fIsection\fR is resizeable; otherwise returns FALSE.
.PP
If \fIsection\fR is -1 then this function applies to all sections, i.e. returns TRUE if all sections are resizeable; otherwise returns FALSE.
.PP
See also setResizeEnabled().
.SH "bool QHeader::isStretchEnabled () const"
Returns TRUE if the header sections always take up the full width (or height) of the header; otherwise returns FALSE. See the "stretching" property for details.
.SH "bool QHeader::isStretchEnabled ( int section ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns TRUE if section \fIsection\fR will resize to take up the full width (or height) of the header; otherwise returns FALSE. If at least one section has stretch enabled the sections will always take up the full width of the header.
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use mapToIndex() instead.
.PP
Translates from logical index \fIl\fR to actual index (index at which the section \fIl\fR is displayed) . Returns -1 if \fIl\fR is outside the legal range.
.PP
See also mapToLogical().
.SH "int QHeader::mapToIndex ( int section ) const"
Returns the index position corresponding to the specified \fIsection\fR number.
.PP
\fBWarning:\fR If QTable is used to move header sections as a result of user interaction, the mapping exposed by this function will not reflect the order of the headers in the table; i.e., QTable does not call moveSection() to move sections but handles move operations internally.
.PP
See also mapToSection().
.SH "int QHeader::mapToLogical ( int a ) const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use mapToSection() instead.
.PP
Translates from actual index \fIa\fR (index at which the section is displayed) to logical index of the section. Returns -1 if \fIa\fR is outside the legal range.
.PP
See also mapToActual().
.SH "int QHeader::mapToSection ( int index ) const"
Returns the number of the section that corresponds to the specified \fIindex\fR.
.PP
\fBWarning:\fR If QTable is used to move header sections as a result of user interaction, the mapping exposed by this function will not reflect the order of the headers in the table; i.e., QTable does not call moveSection() to move sections but handles move operations internally.
.PP
See also mapToIndex().
.SH "void QHeader::moveCell ( int fromIdx, int toIdx )\fC [virtual]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use moveSection() instead.
.PP
Moves the section that is currently displayed at index \fIfromIdx\fR to index \fItoIdx\fR.
.SH "void QHeader::moveSection ( int section, int toIndex )"
Moves section \fIsection\fR to index position \fItoIndex\fR.
.SH "void QHeader::moved ( int fromIndex, int toIndex )\fC [signal]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use indexChange() instead.
.PP
This signal is emitted when the user has moved the section which is displayed at the index \fIfromIndex\fR to the index \fItoIndex\fR.
.SH "int QHeader::offset () const"
Returns the header's left-most (or top-most) visible pixel. See the "offset" property for details.
.SH "Orientation QHeader::orientation () const"
Returns the header's orientation. See the "orientation" property for details.
If \fIenable\fR is TRUE, any clicks on section \fIsection\fR will result in clicked() signals being emitted; otherwise the section will ignore clicks.
.PP
If \fIsection\fR is -1 (the default) then the \fIenable\fR value is set for all existing sections and will be applied to any new sections that are added.
Sets the text of section \fIsection\fR to \fIs\fR. The section's width is set to \fIsize\fR if \fIsize\fR >= 0; otherwise it is left unchanged. Any icon set that has been set for this section remains unchanged.
.PP
If the section does not exist, nothing happens.
.PP
Examples:
.)l chart/setdataform.cpp and table/small-table-demo/main.cpp.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the icon for section \fIsection\fR to \fIiconset\fR and the text to \fIs\fR. The section's width is set to \fIsize\fR if \fIsize\fR >= 0; otherwise it is left unchanged.
If \fIenable\fR is TRUE the user may resize section \fIsection\fR; otherwise the section may not be manually resized.
.PP
If \fIsection\fR is negative (the default) then the \fIenable\fR value is set for all existing sections and will be applied to any new sections that are added. Example:
.PP
.nf
.br
// Allow resizing of all current and future sections
.br
header->setResizeEnabled(TRUE);
.br
// Disable resizing of section 3, (the fourth section added)
.br
header->setResizeEnabled(FALSE, 3);
.br
.fi
.PP
If the user resizes a section, a sizeChange() signal is emitted.
.PP
See also moving, setClickEnabled(), and tracking.
.SH "void QHeader::setSortIndicator ( int section, SortOrder order )"
Sets a sort indicator onto the specified \fIsection\fR. The indicator's \fIorder\fR is either Ascending or Descending.
.PP
Only one section can show a sort indicator at any one time. If you don't want any section to show a sort indicator pass a \fIsection\fR number of -1.
.PP
See also sortIndicatorSection() and sortIndicatorOrder().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use the other overload instead.
.SH "void QHeader::setStretchEnabled ( bool b, int section )\fC [virtual]\fR"
If \fIb\fR is TRUE, section \fIsection\fR will be resized when the header is resized, so that the sections take up the full width (or height for vertical headers) of the header; otherwise section \fIsection\fR will be set to be unstretchable and will not resize when the header is resized.
.PP
If \fIsection\fR is -1, and if \fIb\fR is TRUE, then all sections will be resized equally when the header is resized so that they take up the full width (or height for vertical headers) of the header; otherwise all the sections will be set to be unstretchable and will not resize when the header is resized.
.PP
See also adjustHeaderSize().
.SH "void QHeader::setStretchEnabled ( bool b )"
Sets whether the header sections always take up the full width (or height) of the header to \fIb\fR. See the "stretching" property for details.
Sets whether the sizeChange() signal is emitted continuously to \fIenable\fR. See the "tracking" property for details.
.SH "void QHeader::sizeChange ( int section, int oldSize, int newSize )\fC [signal]\fR"
This signal is emitted when the user has changed the size of a \fIsection\fR from \fIoldSize\fR to \fInewSize\fR. This signal is typically connected to a slot that repaints the table or list that contains the header.
Returns the implied sort order of the QHeaders sort indicator.
.PP
See also setSortIndicator() and sortIndicatorSection().
.SH "int QHeader::sortIndicatorSection () const"
Returns the section showing the sort indicator or -1 if there is no sort indicator.
.PP
See also setSortIndicator() and sortIndicatorOrder().
.SH "bool QHeader::tracking () const"
Returns TRUE if the sizeChange() signal is emitted continuously; otherwise returns FALSE. See the "tracking" property for details.
.SS "Property Documentation"
.SH "int count"
This property holds the number of sections in the header.
.PP
Get this property's value with count().
.SH "bool moving"
This property holds whether the header sections can be moved.
.PP
If this property is TRUE (the default) the user can move sections. If the user moves a section the indexChange() signal is emitted.
.PP
See also setClickEnabled() and setResizeEnabled().
.PP
Set this property's value with setMovingEnabled() and get this property's value with isMovingEnabled().
.SH "int offset"
This property holds the header's left-most (or top-most) visible pixel.
.PP
Setting this property will scroll the header so that \fIoffset\fR becomes the left-most (or top-most for vertical headers) visible pixel.
.PP
Set this property's value with setOffset() and get this property's value with offset().
.SH "Orientation orientation"
This property holds the header's orientation.
.PP
The orientation is either Vertical or Horizontal (the default).
.PP
Call setOrientation() before adding labels if you don't provide a size parameter otherwise the sizes will be incorrect.
.PP
Set this property's value with setOrientation() and get this property's value with orientation().
.SH "bool stretching"
This property holds whether the header sections always take up the full width (or height) of the header.
.PP
Set this property's value with setStretchEnabled() and get this property's value with isStretchEnabled().
.SH "bool tracking"
This property holds whether the sizeChange() signal is emitted continuously.
.PP
If tracking is on, the sizeChange() signal is emitted continuously while the mouse is moved (i.e. when the header is resized), otherwise it is only emitted when the mouse button is released at the end of resizing.
.PP
Tracking defaults to FALSE.
.PP
Set this property's value with setTracking() and get this property's value with tracking().