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

TQHeader Class Reference

The TQHeader class provides a header row or column, e.g. for tables and listviews. More...

#include <ntqheader.h>

Inherits TQWidget.

List of all member functions.

Public Members

Public Slots

Signals

Properties

Protected Members


Detailed Description

The TQHeader class provides a header row or column, e.g. for tables and listviews.

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 TQTable and TQListView for example.

A header is composed of one or more sections, each of which can display a text label and an iconset. A sort indicator (an arrow) can also be displayed using setSortIndicator().

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.

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

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 TQHeader API works in terms of section numbers, so it doesn't matter where a particular section has been moved to.

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.

Here's an example to clarify mapToSection() and mapToIndex():

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 Sect 1

k mapToSection(k) mapToIndex(k)
0 0 0
1 2 3
2 3 1
3 1 2

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.

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

See also TQListView, TQTable, and Advanced Widgets.


Member Function Documentation

TQHeader::TQHeader ( TQWidget * parent = 0, const char * name = 0 )

Constructs a horizontal header called name, with parent parent.

TQHeader::TQHeader ( int n, TQWidget * parent = 0, const char * name = 0 )

Constructs a horizontal header called name, with n sections and parent parent.

TQHeader::~TQHeader ()

Destroys the header and all its sections.

int TQHeader::addLabel ( const TQString & s, int size = -1 )

Adds a new section with label text s. 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 size. If size < 0, an appropriate size for the text s is chosen.

int TQHeader::addLabel ( const TQIconSet & iconset, const TQString & s, int size = -1 )

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

Adds a new section with iconset iconset and label text s. 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 size, unless size is negative in which case the size is calculated taking account of the size of the text.

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

int TQHeader::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 TQHeader::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 TQHeader::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 TQHeader::clicked ( int section ) [signal]

If isClickEnabled() is TRUE, this signal is emitted when the user clicks section section.

See also pressed() and released().

int TQHeader::count () const

Returns the number of sections in the header. See the "count" property for details.

int TQHeader::headerWidth () const

Returns the total width of all the header columns.

TQIconSet * TQHeader::iconSet ( int section ) const

Returns the icon set for section section. If the section does not exist, 0 is returned.

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

This signal is emitted when the user moves section section from index position fromIndex, to index position toIndex.

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

Returns TRUE if section section is clickable; otherwise returns FALSE.

If section is out of range (negative or larger than count() - 1): returns TRUE if all sections are clickable; otherwise returns FALSE.

See also setClickEnabled().

bool TQHeader::isMovingEnabled () const

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

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

Returns TRUE if section section is resizeable; otherwise returns FALSE.

If section is -1 then this function applies to all sections, i.e. returns TRUE if all sections are resizeable; otherwise returns FALSE.

See also setResizeEnabled().

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

bool TQHeader::isStretchEnabled ( int section ) const

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

Returns TRUE if section section 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.

See also setStretchEnabled().

TQString TQHeader::label ( int section ) const

Returns the text for section section. If the section does not exist, a TQString::null is returned.

Example: helpsystem/tooltip.cpp.

int TQHeader::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 TQHeader::mapToIndex ( int section ) const

Returns the index position corresponding to the specified section number.

Warning: If TQTable 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., TQTable does not call moveSection() to move sections but handles move operations internally.

See also mapToSection().

int TQHeader::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 TQHeader::mapToSection ( int index ) const

Returns the number of the section that corresponds to the specified index.

Warning: If TQTable 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., TQTable does not call moveSection() to move sections but handles move operations internally.

See also mapToIndex().

void TQHeader::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 TQHeader::moveSection ( int section, int toIndex )

Moves section section to index position toIndex.

void TQHeader::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 TQHeader::offset () const

Returns the header's left-most (or top-most) visible pixel. See the "offset" property for details.

Orientation TQHeader::orientation () const

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

void TQHeader::paintSection ( TQPainter * p, int index, const TQRect & fr ) [virtual protected]

Paints the section at position index, inside rectangle fr (which uses widget coordinates) using painter p.

Calls paintSectionLabel().

void TQHeader::paintSectionLabel ( TQPainter * p, int index, const TQRect & fr ) [virtual protected]

Paints the label of the section at position index, inside rectangle fr (which uses widget coordinates) using painter p.

Called by paintSection()

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

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

See also released().

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

This signal is emitted when section section is released.

See also pressed().

void TQHeader::removeLabel ( int section )

Removes section section. If the section does not exist, nothing happens.

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

Resizes section section to s pixels wide (or high).

TQRect TQHeader::sRect ( int index ) [protected]

Returns the rectangle covered by the section at index index.

int TQHeader::sectionAt ( int pos ) const

Returns the index of the section which contains the position pos given in pixels from the left (or top).

See also offset.

Example: helpsystem/tooltip.cpp.

void TQHeader::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).

void TQHeader::sectionHandleDoubleClicked ( int section ) [signal]

This signal is emitted when the user doubleclicks on the edge (handle) of section section.

int TQHeader::sectionPos ( int section ) const

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

See also offset.

TQRect TQHeader::sectionRect ( int section ) const

Returns the rectangle covered by section section.

Example: helpsystem/tooltip.cpp.

int TQHeader::sectionSize ( int section ) const

Returns the width (or height) of the section in pixels.

void TQHeader::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 TQHeader::setClickEnabled ( bool enable, int section = -1 ) [virtual]

If enable is TRUE, any clicks on section section will result in clicked() signals being emitted; otherwise the section will ignore clicks.

If section is -1 (the default) then the enable value is set for all existing sections and will be applied to any new sections that are added.

See also moving and setResizeEnabled().

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

Sets the text of section section to s. The section's width is set to size if size >= 0; otherwise it is left unchanged. Any icon set that has been set for this section remains unchanged.

If the section does not exist, nothing happens.

Examples: chart/setdataform.cpp and table/small-table-demo/main.cpp.

void TQHeader::setLabel ( int section, const TQIconSet & iconset, const TQString & s, int size = -1 ) [virtual]

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

Sets the icon for section section to iconset and the text to s. The section's width is set to size if size >= 0; otherwise it is left unchanged.

If the section does not exist, nothing happens.

void TQHeader::setMovingEnabled ( bool ) [virtual]

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

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

Sets the header's left-most (or top-most) visible pixel to pos. See the "offset" property for details.

void TQHeader::setOrientation ( Orientation ) [virtual]

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

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

If enable is TRUE the user may resize section section; otherwise the section may not be manually resized.

If section is negative (the default) then the enable value is set for all existing sections and will be applied to any new sections that are added. Example:

    // Allow resizing of all current and future sections
    header->setResizeEnabled(TRUE);
    // Disable resizing of section 3, (the fourth section added)
    header->setResizeEnabled(FALSE, 3);
    

If the user resizes a section, a sizeChange() signal is emitted.

See also moving, setClickEnabled(), and tracking.

void TQHeader::setSortIndicator ( int section, SortOrder order )

Sets a sort indicator onto the specified section. The indicator's order is either Ascending or Descending.

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 section number of -1.

See also sortIndicatorSection() and sortIndicatorOrder().

void TQHeader::setSortIndicator ( int section, bool ascending = TRUE )

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

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

Use the other overload instead.

void TQHeader::setStretchEnabled ( bool b, int section ) [virtual]

If b is TRUE, section section 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 section will be set to be unstretchable and will not resize when the header is resized.

If section is -1, and if b 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.

See also adjustHeaderSize().

void TQHeader::setStretchEnabled ( bool b )

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

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

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

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

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

SortOrder TQHeader::sortIndicatorOrder () const

Returns the implied sort order of the TQHeaders sort indicator.

See also setSortIndicator() and sortIndicatorSection().

int TQHeader::sortIndicatorSection () const

Returns the section showing the sort indicator or -1 if there is no sort indicator.

See also setSortIndicator() and sortIndicatorOrder().

bool TQHeader::tracking () const

Returns TRUE if the sizeChange() signal is emitted continuously; 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 this property is TRUE (the default) the user can move sections. If the user moves a section the indexChange() signal is emitted.

See also setClickEnabled() and setResizeEnabled().

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

int offset

This property holds the header's left-most (or top-most) visible pixel.

Setting this property will scroll the header so that offset becomes the left-most (or top-most 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 orientation.

The orientation is either Vertical or Horizontal (the default).

Call setOrientation() before adding labels if you don't provide a size parameter otherwise the sizes will be incorrect.

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 take up the full width (or height) of the header.

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

bool tracking

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

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.

Tracking defaults to FALSE.

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


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8