
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQ3Header class provides a header row or column, e.g. for tables and listviews.More...
| Header: | #include <Q3Header> |
| Inherits: | QWidget |
|
| Q3Header(QWidget * parent = 0, const char * name = 0) | |
| Q3Header(int n, QWidget * parent = 0, const char * name = 0) | |
| ~Q3Header() | |
| int | addLabel(const QString & s, int size = -1) |
| int | addLabel(const QIcon & icon, const QString & s, int size = -1) |
| void | adjustHeaderSize() |
| int | cellAt(int pos) const |
| int | cellPos(int i) const |
| int | cellSize(int i) const |
| int | count() const |
| int | headerWidth() const |
| QIcon * | iconSet(int section) const |
| bool | isClickEnabled(int section = -1) const |
| bool | isMovingEnabled() const |
| bool | isResizeEnabled(int section = -1) const |
| bool | isStretchEnabled() const |
| bool | isStretchEnabled(int section) const |
| QString | label(int section) const |
| int | mapToActual(int l) const |
| int | mapToIndex(int section) const |
| int | mapToLogical(int a) const |
| int | mapToSection(int index) const |
| virtual void | moveCell(int fromIdx, int toIdx) |
| void | moveSection(int section, int toIndex) |
| int | offset() const |
| Qt::Orientation | orientation() const |
| void | removeLabel(int section) |
| void | resizeSection(int section, int s) |
| int | sectionAt(int pos) const |
| int | sectionPos(int section) const |
| QRect | sectionRect(int section) const |
| int | sectionSize(int section) const |
| virtual void | setCellSize(int section, int s) |
| virtual void | setClickEnabled(bool enable, int section = -1) |
| virtual void | setLabel(int section, const QString & s, int size = -1) |
| virtual void | setLabel(int section, const QIcon & icon, const QString & s, int size = -1) |
| virtual void | setMovingEnabled(bool) |
| virtual void | setOrientation(Qt::Orientation) |
| virtual void | setResizeEnabled(bool enable, int section = -1) |
| void | setSortIndicator(int section, Qt::SortOrder order) |
| void | setSortIndicator(int section, bool ascending = true) |
| virtual void | setStretchEnabled(bool b, int section) |
| void | setStretchEnabled(bool b) |
| virtual void | setTracking(bool enable) |
| Qt::SortOrder | sortIndicatorOrder() const |
| int | sortIndicatorSection() const |
| bool | tracking() const |
| virtual QSize | sizeHint() const |
| virtual void | setOffset(int pos) |
| void | clicked(int section) |
| void | indexChange(int section, int fromIndex, int toIndex) |
| void | moved(int fromIndex, int toIndex) |
| void | pressed(int section) |
| void | released(int section) |
| void | sectionClicked(int index) |
| void | sectionHandleDoubleClicked(int section) |
| void | sizeChange(int section, int oldSize, int newSize) |
| virtual void | paintSection(QPainter * p, int index, const QRect & fr) |
| virtual void | paintSectionLabel(QPainter * p, int index, const QRect & fr) |
| QRect | sRect(int index) |
| virtual void | changeEvent(QEvent * ev) |
| virtual void | keyPressEvent(QKeyEvent * e) |
| virtual void | keyReleaseEvent(QKeyEvent * e) |
| virtual void | mouseDoubleClickEvent(QMouseEvent * e) |
| virtual void | mouseMoveEvent(QMouseEvent * e) |
| virtual void | mousePressEvent(QMouseEvent * e) |
| virtual void | mouseReleaseEvent(QMouseEvent * e) |
| virtual void | paintEvent(QPaintEvent * e) |
| virtual void | resizeEvent(QResizeEvent * e) |
| virtual void | showEvent(QShowEvent * e) |
TheQ3Header 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 byQ3Table andQ3ListView for example.
A header is composed of one or moresections, each of which can display a text label and anicon. A sort indicator (an arrow) can also be displayed usingsetSortIndicator().
Sections are added withaddLabel() and removed withremoveLabel(). The label and icon are set inaddLabel() and can be changed later withsetLabel(). Usecount() to retrieve the number of sections in the header.
The orientation of the header is set withsetOrientation(). IfsetStretchEnabled() 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 ifsetResizeEnabled() is true. CalladjustHeaderSize() to have the sections resize to occupy the full width (or height).
A section can be moved withmoveSection(). IfsetMovingEnabled() 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 (withaddLabel()), may not be the same after the move. You don't have to worry about this in practice because theQ3Header 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 callmapToIndex() giving it the section number. (This is the number returned by theaddLabel() call which created the section.) If you want to get the section number of a section at a particular index position callmapToSection() giving it the index number.
Here's an example to clarifymapToSection() andmapToIndex():
| 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 callmapToSection(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 callmapToIndex(2) and get an index of 1.
Q3Header provides theclicked(),pressed() andreleased() signals. If the user changes the size of a section, thesizeChange() signal is emitted. If you want to have asizeChange() signal emitted continuously whilst the user is resizing (rather than just after the resizing is finished), usesetTracking(). If the user moves a section theindexChange() signal is emitted.
See alsoQ3ListView andQ3Table.
This property holds the number of sections in the header.
Access functions:
| int | count() const |
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 theindexChange() signal is emitted.
Access functions:
| bool | isMovingEnabled() const |
| virtual void | setMovingEnabled(bool) |
See alsosetClickEnabled() andsetResizeEnabled().
This property holds the header's left-most (or top-most) visible pixel.
Setting this property will scroll the header so thatoffset becomes the left-most (or top-most for vertical headers) visible pixel.
Access functions:
| int | offset() const |
| virtual void | setOffset(int pos) |
This property holds the header's orientation.
The orientation is eitherQt::Vertical orQt::Horizontal (the default).
Call setOrientation() before adding labels if you don't provide a size parameter otherwise the sizes will be incorrect.
Access functions:
| Qt::Orientation | orientation() const |
| virtual void | setOrientation(Qt::Orientation) |
This property holds whether the header sections always take up the full width (or height) of the header.
Access functions:
| bool | isStretchEnabled() const |
| bool | isStretchEnabled(int section) const |
| virtual void | setStretchEnabled(bool b, int section) |
| void | setStretchEnabled(bool b) |
This property holds whether the sizeChange() signal is emitted continuously.
If tracking is on, thesizeChange() 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.
Access functions:
| bool | tracking() const |
| virtual void | setTracking(bool enable) |
Constructs a horizontal header calledname, with parentparent.
Constructs a horizontal header calledname, withn sections and parentparent.
Destroys the header and all its sections.
Adds a new section with label texts. 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 tosize. Ifsize < 0, an appropriate size for the texts is chosen.
This is an overloaded function.
Adds a new section with iconicon and label texts. 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 tosize, unless size is negative in which case the size is calculated taking account of the size of the text.
Adjusts the size of the sections to fit the size of the header as completely as possible. Only sections for whichisStretchEnabled() is true will be resized.
UsesectionAt() instead.
Returns the index at which the section is displayed, which containspos in widget coordinates, or -1 ifpos is outside the header sections.
UsesectionPos() instead.
Returns the position in pixels of the section that is displayed at the indexi. The position is measured from the start of the header.
UsesectionSize() instead.
Returns the size in pixels of the section that is displayed at the indexi.
See alsosetCellSize().
[virtual protected]void Q3Header::changeEvent(QEvent * ev)Reimplemented fromQWidget::changeEvent().
[signal]void Q3Header::clicked(int section)IfisClickEnabled() is true, this signal is emitted when the user clicks sectionsection.
See alsopressed() andreleased().
Returns the total width of all the header columns.
Returns the icon set for sectionsection. If the section does not exist, 0 is returned.
[signal]void Q3Header::indexChange(int section,int fromIndex,int toIndex)This signal is emitted when the user moves sectionsection from index positionfromIndex, to index positiontoIndex.
Returns true if sectionsection is clickable; otherwise returns false.
Ifsection is out of range (negative or larger thancount() - 1): returns true if all sections are clickable; otherwise returns false.
See alsosetClickEnabled().
Returns true if sectionsection is resizeable; otherwise returns false.
Ifsection is -1 then this function applies to all sections, i.e. returns true if all sections are resizeable; otherwise returns false.
See alsosetResizeEnabled().
[virtual protected]void Q3Header::keyPressEvent(QKeyEvent * e)Reimplemented fromQWidget::keyPressEvent().
[virtual protected]void Q3Header::keyReleaseEvent(QKeyEvent * e)Reimplemented fromQWidget::keyReleaseEvent().
Returns the text for sectionsection. If the section does not exist, returns an empty string.
See alsosetLabel().
UsemapToIndex() instead.
Translates from logical indexl to actual index (index at which the sectionl is displayed) . Returns -1 ifl is outside the legal range.
See alsomapToLogical().
Returns the index position at which sectionsection is displayed.
UsemapToSection() instead.
Translates from actual indexa (index at which the section is displayed) to logical index of the section. Returns -1 ifa is outside the legal range.
See alsomapToActual().
Returns the number of the section that is displayed at index positionindex.
[virtual protected]void Q3Header::mouseDoubleClickEvent(QMouseEvent * e)Reimplemented fromQWidget::mouseDoubleClickEvent().
[virtual protected]void Q3Header::mouseMoveEvent(QMouseEvent * e)Reimplemented fromQWidget::mouseMoveEvent().
[virtual protected]void Q3Header::mousePressEvent(QMouseEvent * e)Reimplemented fromQWidget::mousePressEvent().
[virtual protected]void Q3Header::mouseReleaseEvent(QMouseEvent * e)Reimplemented fromQWidget::mouseReleaseEvent().
[virtual]void Q3Header::moveCell(int fromIdx,int toIdx)UsemoveSection() instead.
Moves the section that is currently displayed at indexfromIdx to indextoIdx.
Moves sectionsection to index positiontoIndex.
[signal]void Q3Header::moved(int fromIndex,int toIndex)UseindexChange() instead.
This signal is emitted when the user has moved the section which is displayed at the indexfromIndex to the indextoIndex.
[virtual protected]void Q3Header::paintEvent(QPaintEvent * e)Reimplemented fromQWidget::paintEvent().
[virtual protected]void Q3Header::paintSection(QPainter * p,int index, constQRect & fr)Paints the section at positionindex, inside rectanglefr (which uses widget coordinates) using painterp.
CallspaintSectionLabel().
[virtual protected]void Q3Header::paintSectionLabel(QPainter * p,int index, constQRect & fr)Paints the label of the section at positionindex, inside rectanglefr (which uses widget coordinates) using painterp.
Called bypaintSection()
[signal]void Q3Header::pressed(int section)This signal is emitted when the user presses sectionsection down.
See alsoreleased().
[signal]void Q3Header::released(int section)This signal is emitted when sectionsection is released.
See alsopressed().
Removes sectionsection. If the section does not exist, nothing happens.
[virtual protected]void Q3Header::resizeEvent(QResizeEvent * e)Reimplemented fromQWidget::resizeEvent().
Resizes sectionsection tos pixels wide (or high).
[protected]QRect Q3Header::sRect(int index)Returns the rectangle covered by the section at indexindex.
Returns the index of the section which contains the positionpos given in pixels from the left (or top).
See alsooffset().
[signal]void Q3Header::sectionClicked(int index)Useclicked() 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).
[signal]void Q3Header::sectionHandleDoubleClicked(int section)This signal is emitted when the user doubleclicks on the edge (handle) of sectionsection.
Returns the position (in pixels) at which thesection starts.
See alsooffset().
Returns the rectangle covered by sectionsection.
Returns the width (or height) of thesection in pixels.
[virtual]void Q3Header::setCellSize(int section,int s)UseresizeSection() instead.
Sets the size of the sectionsection tos pixels.
Warning: does not repaint or send out signals
See alsocellSize().
[virtual]void Q3Header::setClickEnabled(bool enable,int section = -1)Ifenable is true, any clicks on sectionsection will result inclicked() signals being emitted; otherwise the section will ignore clicks.
Ifsection is -1 (the default) then theenable value is set for all existing sections and will be applied to any new sections that are added.
See alsoisClickEnabled(),setMovingEnabled(), andsetResizeEnabled().
[virtual]void Q3Header::setLabel(int section, constQString & s,int size = -1)Sets the text of sectionsection tos. The section's width is set tosize ifsize >= 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.
See alsolabel().
[virtual]void Q3Header::setLabel(int section, constQIcon & icon, constQString & s,int size = -1)This is an overloaded function.
Sets the icon for sectionsection toicon and the text tos. The section's width is set tosize ifsize >= 0; otherwise it is left unchanged.
If the section does not exist, nothing happens.
[virtual]void Q3Header::setResizeEnabled(bool enable,int section = -1)Ifenable is true the user may resize sectionsection; otherwise the section may not be manually resized.
Ifsection is negative (the default) then theenable 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 sectionsheader->setResizeEnabled(true);// Disable resizing of section 3, (the fourth section added)header->setResizeEnabled(false,3);
If the user resizes a section, asizeChange() signal is emitted.
See alsoisResizeEnabled(),setMovingEnabled(),setClickEnabled(), andsetTracking().
Sets a sort indicator onto the specifiedsection. The indicator'sorder 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 asection number of -1.
See alsosortIndicatorSection() andsortIndicatorOrder().
This is an overloaded function.
Sets the sort indicator toascending. Use the other overload instead.
[virtual protected]void Q3Header::showEvent(QShowEvent * e)Reimplemented fromQWidget::showEvent().
[signal]void Q3Header::sizeChange(int section,int oldSize,int newSize)This signal is emitted when the user has changed the size of asection fromoldSize tonewSize. This signal is typically connected to a slot that repaints the table or list that contains the header.
[virtual]QSize Q3Header::sizeHint() constReimplemented fromQWidget::sizeHint().
Returns the implied sort order of the Q3Headers sort indicator.
See alsosetSortIndicator() andsortIndicatorSection().
Returns the section showing the sort indicator or -1 if there is no sort indicator.
See alsosetSortIndicator() andsortIndicatorOrder().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.