The PySide.QtGui.QHeaderView class provides a header row or header column for item views.
A PySide.QtGui.QHeaderView displays the headers used in item views such as the PySide.QtGui.QTableView and PySide.QtGui.QTreeView classes. It takes the place of Qt3’s QHeader class previously used for the same purpose, but uses the Qt’s model/view architecture for consistency with the item view classes.
The PySide.QtGui.QHeaderView class is one of the Model/View Classes and is part of Qt’s model/view framework .
The header gets the data for each section from the model using the QAbstractItemModel.headerData() function. You can set the data by using QAbstractItemModel.setHeaderData() .
Each header has an PySide.QtGui.QHeaderView.orientation() and a number of sections, given by the PySide.QtGui.QHeaderView.count() function. A section refers to a part of the header - either a row or a column, depending on the orientation.
Sections can be moved and resized using PySide.QtGui.QHeaderView.moveSection() and PySide.QtGui.QHeaderView.resizeSection() ; they can also be hidden and shown with PySide.QtGui.QHeaderView.hideSection() and PySide.QtGui.QHeaderView.showSection() .
Each section of a header is described by a section ID, specified by its section() , and can be located at a particular PySide.QtGui.QHeaderView.visualIndex() in the header. A section can have a sort indicator set with PySide.QtGui.QHeaderView.setSortIndicator() ; this indicates whether the items in the associated item view will be sorted in the order given by the section.
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.
A header can be fixed in place, or made movable with PySide.QtGui.QHeaderView.setMovable() . It can be made clickable with PySide.QtGui.QHeaderView.setClickable() , and has resizing behavior in accordance with PySide.QtGui.QHeaderView.setResizeMode() .
Note
Double-clicking on a header to resize a section only applies for visible rows.
A header will emit PySide.QtGui.QHeaderView.sectionMoved() if the user moves a section, PySide.QtGui.QHeaderView.sectionResized() if the user resizes a section, and PySide.QtGui.QHeaderView.sectionClicked() as well as PySide.QtGui.QHeaderView.sectionHandleDoubleClicked() in response to mouse clicks. A header will also emit PySide.QtGui.QHeaderView.sectionCountChanged() and PySide.QtGui.QHeaderView.sectionAutoResize() .
You can identify a section using the PySide.QtGui.QHeaderView.logicalIndex() and PySide.QtGui.QHeaderView.logicalIndexAt() functions, or by its index position, using the PySide.QtGui.QHeaderView.visualIndex() and PySide.QtGui.QHeaderView.visualIndexAt() functions. The visual index will change if a section is moved, but the logical index will not change.
PySide.QtGui.QTableWidget and PySide.QtGui.QTableView create default headers. If you want the headers to be visible, you can use PySide.QtGui.QFrame.setVisible() .
Not all Qt.ItemDataRole s will have an effect on a PySide.QtGui.QHeaderView . If you need to draw other roles, you can subclass PySide.QtGui.QHeaderView and reimplement PySide.QtGui.QHeaderView.paintEvent() . PySide.QtGui.QHeaderView respects the following item data roles: TextAlignmentRole , DisplayRole , FontRole , DecorationRole , ForegroundRole , and BackgroundRole .
Note
Each header renders the data for each section itself, and does not rely on a delegate. As a result, calling a header’s PySide.QtGui.QAbstractItemView.setItemDelegate() function will have no effect.
See also
Model/View Programming PySide.QtGui.QListView PySide.QtGui.QTableView PySide.QtGui.QTreeView
Parameters: |
|
---|
The resize mode specifies the behavior of the header sections. It can be set on the entire header view or on individual sections using PySide.QtGui.QHeaderView.setResizeMode() .
Constant | Description |
---|---|
QHeaderView.Interactive | The user can resize the section. The section can also be resized programmatically using PySide.QtGui.QHeaderView.resizeSection() . The section size defaults to PySide.QtGui.QHeaderView.defaultSectionSize() . (See also PySide.QtGui.QHeaderView.cascadingSectionResizes() .) |
QHeaderView.Fixed | The user cannot resize the section. The section can only be resized programmatically using PySide.QtGui.QHeaderView.resizeSection() . The section size defaults to PySide.QtGui.QHeaderView.defaultSectionSize() . |
QHeaderView.Stretch | PySide.QtGui.QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically. |
QHeaderView.ResizeToContents | PySide.QtGui.QHeaderView will automatically resize the section to its optimal size based on the contents of the entire column or row. The size cannot be changed by the user or programmatically. (This value was introduced in 4.2) |
The following values are obsolete:
Constant | Description |
---|---|
QHeaderView.Custom | Use Fixed instead. |
Return type: | PySide.QtCore.bool |
---|
This property holds whether interactive resizing will be cascaded to the following sections once the section being resized by the user has reached its minimum size.
This property only affects sections that have Interactive as their resize mode.
The default value is false.
Return type: | PySide.QtCore.int |
---|
Returns the number of sections in the header.
Return type: | PySide.QtCore.Qt.Alignment |
---|
This property holds the default alignment of the text in each header section.
Return type: | PySide.QtCore.int |
---|
This property holds the default size of the header sections before resizing..
This property only affects sections that have Interactive or Fixed as their resize mode.
Parameters: |
|
---|
Return type: | PySide.QtCore.int |
---|
Returns the number of sections in the header that has been hidden.
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Hides the section specified by logicalIndex .
Return type: | PySide.QtCore.bool |
---|
This property holds whether the sections containing selected items are highlighted.
By default, this property is false.
Parameters: | option – PySide.QtGui.QStyleOptionHeader |
---|
Initialize option with the values from this PySide.QtGui.QHeaderView . This method is useful for subclasses when they need a PySide.QtGui.QStyleOptionHeader , but do not want to fill in all the information themselves.
See also
Parameters: |
|
---|
Return type: | PySide.QtCore.bool |
---|
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.
Return type: | PySide.QtCore.bool |
---|
Returns true if the header can be moved by the user; otherwise returns false.
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
This property holds whether the sort indicator is shown.
By default, this property is false.
Return type: | PySide.QtCore.int |
---|
Returns the length along the orientation of the header.
See also
PySide.QtGui.QHeaderView.sizeHint() PySide.QtGui.QHeaderView.setResizeMode() PySide.QtGui.QHeaderView.offset()
Parameters: | visualIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 or visualIndex >= QHeaderView.count() .
Note that the visualIndex is not affected by hidden sections.
Parameters: |
|
---|---|
Return type: | PySide.QtCore.int |
Returns the logical index of the section at the given coordinate. If the header is horizontal x will be used, otherwise y will be used to find the logical index.
Parameters: | position – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the section that covers the given position in the viewport.
Parameters: | pos – PySide.QtCore.QPoint |
---|---|
Return type: | PySide.QtCore.int |
Returns the logical index of the section at the position given in pos . If the header is horizontal the x-coordinate will be used, otherwise the y-coordinate will be used to find the logical index.
Return type: | PySide.QtCore.int |
---|
This property holds the minimum size of the header sections..
The minimum section size is the smallest section size allowed. If the minimum section size is set to -1, PySide.QtGui.QHeaderView will use the maximum of the global strut or the font metrics size.
This property is honored by all resize modes .
Parameters: |
|
---|
Moves the section at visual index from to occupy visual index to .
Return type: | PySide.QtCore.int |
---|
Returns the offset of the header: this is the header’s left-most (or top-most for vertical headers) visible pixel.
See also
Return type: | PySide.QtCore.Qt.Orientation |
---|
Returns the orientation of the header.
See also
Qt.Orientation
Parameters: |
|
---|
Paints the section specified by the given logicalIndex , using the given painter and rect .
Normally, you do not have to call this function.
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtGui.QHeaderView.ResizeMode |
Returns the resize mode that applies to the section specified by the given logicalIndex .
Parameters: |
|
---|
Resizes the section specified by logicalIndex to size measured in pixels.
Resizes the sections according to their size hints. Normally, you do not have to call this function.
Parameters: | mode – PySide.QtGui.QHeaderView.ResizeMode |
---|
Parameters: | state – PySide.QtCore.QByteArray |
---|---|
Return type: | PySide.QtCore.bool |
Restores the state of this header view. This function returns true if the state was restored; otherwise returns false.
See also
Return type: | PySide.QtCore.QByteArray |
---|
Saves the current state of this header view.
To restore the saved state, pass the return value to PySide.QtGui.QHeaderView.restoreState() .
Parameters: |
|
---|
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Parameters: |
|
---|
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Parameters: |
|
---|
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the section position of the given logicalIndex , or -1 if the section is hidden.
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Parameters: |
|
---|
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the width (or height for vertical headers) of the given logicalIndex .
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.QSize |
Returns the size of the contents of the section specified by the given logicalIndex .
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns a suitable size hint for the section specified by logicalIndex .
See also
PySide.QtGui.QHeaderView.sizeHint() PySide.QtGui.QHeaderView.defaultSectionSize() PySide.QtGui.QHeaderView.minimumSectionSize() Qt.SizeHintRole
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the section viewport position of the given logicalIndex .
If the section is hidden, the return value is undefined.
Parameters: |
|
---|
This slot is called when sections are removed from the parent . logicalFirst and logicalLast signify where the sections were removed.
If only one section is removed, logicalFirst and logicalLast will be the same.
Return type: | PySide.QtCore.bool |
---|
Returns true if sections in the header has been hidden; otherwise returns false;
Parameters: |
|
---|
This slot is called when sections are inserted into the parent . logicalFirst and logicalLast indices signify where the new sections were inserted.
If only one section is inserted, logicalFirst and logicalLast will be the same.
Return type: | PySide.QtCore.bool |
---|
Returns true if sections in the header has been moved; otherwise returns false;
Parameters: | enable – PySide.QtCore.bool |
---|
This property holds whether interactive resizing will be cascaded to the following sections once the section being resized by the user has reached its minimum size.
This property only affects sections that have Interactive as their resize mode.
The default value is false.
Parameters: | clickable – PySide.QtCore.bool |
---|
If clickable is true, the header will respond to single clicks.
Parameters: | alignment – PySide.QtCore.Qt.Alignment |
---|
This property holds the default alignment of the text in each header section.
Parameters: | size – PySide.QtCore.int |
---|
This property holds the default size of the header sections before resizing..
This property only affects sections that have Interactive or Fixed as their resize mode.
Parameters: | highlight – PySide.QtCore.bool |
---|
This property holds whether the sections containing selected items are highlighted.
By default, this property is false.
Parameters: | size – PySide.QtCore.int |
---|
This property holds the minimum size of the header sections..
The minimum section size is the smallest section size allowed. If the minimum section size is set to -1, PySide.QtGui.QHeaderView will use the maximum of the global strut or the font metrics size.
This property is honored by all resize modes .
Parameters: | movable – PySide.QtCore.bool |
---|
If movable is true, the header may be moved by the user; otherwise it is fixed in place.
Parameters: | offset – PySide.QtCore.int |
---|
Sets the header’s offset to offset .
Sets the offset to make the last section visible.
Parameters: | visualIndex – PySide.QtCore.int |
---|
Sets the offset to the start of the section at the given visualIndex .
Parameters: |
|
---|
This is an overloaded function.
Sets the constraints on how the section specified by logicalIndex in the header can be resized to those described by the given mode . The logical index should exist at the time this function is called.
Note
This setting will be ignored for the last section if the PySide.QtGui.QHeaderView.stretchLastSection() property is set to true. This is the default for the horizontal headers provided by PySide.QtGui.QTreeView .
Parameters: | mode – PySide.QtGui.QHeaderView.ResizeMode |
---|
Sets the constraints on how the header can be resized to those described by the given mode .
Parameters: |
|
---|
If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown.
Parameters: |
|
---|
Parameters: | show – PySide.QtCore.bool |
---|
This property holds whether the sort indicator is shown.
By default, this property is false.
Parameters: | stretch – PySide.QtCore.bool |
---|
This property holds whether the last visible section in the header takes up all the available space.
The default value is false.
Note
The horizontal headers provided by PySide.QtGui.QTreeView are configured with this property set to true, ensuring that the view does not waste any of the space assigned to it for its header. If this value is set to true, this property will override the resize mode set on the last section in the header.
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Shows the section specified by logicalIndex .
Parameters: |
|
---|
Return type: | PySide.QtCore.Qt.SortOrder |
---|
Returns the order for the sort indicator. If no section has a sort indicator the return value of this function is undefined.
Return type: | PySide.QtCore.int |
---|
Returns the logical index of the section that has a sort indicator. By default this is section 0.
Return type: | PySide.QtCore.bool |
---|
This property holds whether the last visible section in the header takes up all the available space.
The default value is false.
Note
The horizontal headers provided by PySide.QtGui.QTreeView are configured with this property set to true, ensuring that the view does not waste any of the space assigned to it for its header. If this value is set to true, this property will override the resize mode set on the last section in the header.
Return type: | PySide.QtCore.int |
---|
Returns the number of sections that are set to resize mode stretch. In views, this can be used to see if the headerview needs to resize the sections when the view’s geometry changes.
Parameters: |
|
---|
Swaps the section at visual index first with the section at visual index second .
Parameters: | logicalIndex – PySide.QtCore.int |
---|
Updates the section specified by the given logicalIndex .
Parameters: | logicalIndex – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the visual index position of the section specified by the given logicalIndex , or -1 otherwise.
Hidden sections still have valid visual indexes.
Parameters: | position – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the visual index of the section that covers the given position in the viewport.