Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QHeaderView Class Reference

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

#include <qheaderview.h>

+ Inheritance diagram for QHeaderView:
+ Collaboration diagram for QHeaderView:

Public Types

enum  ResizeMode {
  Interactive , Stretch , Fixed , ResizeToContents ,
  Custom = Fixed
}
 The resize mode specifies the behavior of the header sections. More...
 
- Public Types inherited from QAbstractItemView
enum  SelectionMode {
  NoSelection , SingleSelection , MultiSelection , ExtendedSelection ,
  ContiguousSelection
}
 This enum indicates how the view responds to user selections: More...
 
enum  SelectionBehavior { SelectItems , SelectRows , SelectColumns }
 \value SelectItems Selecting single items. More...
 
enum  ScrollHint { EnsureVisible , PositionAtTop , PositionAtBottom , PositionAtCenter }
 \value EnsureVisible Scroll to ensure that the item is visible. More...
 
enum  EditTrigger {
  NoEditTriggers = 0 , CurrentChanged = 1 , DoubleClicked = 2 , SelectedClicked = 4 ,
  EditKeyPressed = 8 , AnyKeyPressed = 16 , AllEditTriggers = 31
}
 This enum describes actions which will initiate item editing. More...
 
enum  ScrollMode { ScrollPerItem , ScrollPerPixel }
 Describes how the scrollbar should behave. More...
 

Public Slots

void setOffset (int offset)
 Sets the header's offset to offset.
 
void setOffsetToSectionPosition (int visualIndex)
 Sets the offset to the start of the section at the given visualSectionNumber.
 
void setOffsetToLastSection ()
 Sets the offset to make the last section visible.
 
void headerDataChanged (Qt::Orientation orientation, int logicalFirst, int logicalLast)
 Updates the changed header sections with the given orientation, from logicalFirst to logicalLast inclusive.
 
- Public Slots inherited from QAbstractItemView
virtual void setRootIndex (const QModelIndex &index)
 Sets the root item to the item at the given index.
 
virtual void selectAll ()
 Selects all items in the view.
 
void edit (const QModelIndex &index)
 Starts editing the item corresponding to the given index if it is editable.
 
void clearSelection ()
 Deselects all selected items.
 
void setCurrentIndex (const QModelIndex &index)
 Sets the current item to be the item at index.
 
void scrollToTop ()
 Scrolls the view to the top.
 
void scrollToBottom ()
 Scrolls the view to the bottom.
 
void update (const QModelIndex &index)
 Updates the area occupied by the given index.
 

Signals

void sectionMoved (int logicalIndex, int oldVisualIndex, int newVisualIndex)
 This signal is emitted when a section is moved.
 
void sectionResized (int logicalIndex, int oldSize, int newSize)
 This signal is emitted when a section is resized.
 
void sectionPressed (int logicalIndex)
 This signal is emitted when a section is pressed.
 
void sectionClicked (int logicalIndex)
 This signal is emitted when a section is clicked.
 
void sectionEntered (int logicalIndex)
 This signal is emitted when the cursor moves over the section and the left mouse button is pressed.
 
void sectionDoubleClicked (int logicalIndex)
 This signal is emitted when a section is double-clicked.
 
void sectionCountChanged (int oldCount, int newCount)
 This signal is emitted when the number of sections changes, i.e., when sections are added or deleted.
 
void sectionHandleDoubleClicked (int logicalIndex)
 This signal is emitted when a section is double-clicked.
 
void geometriesChanged ()
 This signal is emitted when the header's geometries have changed.
 
void sortIndicatorChanged (int logicalIndex, Qt::SortOrder order)
 This signal is emitted when the section containing the sort indicator or the order indicated is changed.
 
void sortIndicatorClearableChanged (bool clearable)
 
- Signals inherited from QAbstractItemView
void pressed (const QModelIndex &index)
 This signal is emitted when a mouse button is pressed.
 
void clicked (const QModelIndex &index)
 This signal is emitted when a mouse button is left-clicked.
 
void doubleClicked (const QModelIndex &index)
 This signal is emitted when a mouse button is double-clicked.
 
void activated (const QModelIndex &index)
 This signal is emitted when the item specified by index is activated by the user.
 
void entered (const QModelIndex &index)
 This signal is emitted when the mouse cursor enters the item specified by index.
 
void viewportEntered ()
 This signal is emitted when the mouse cursor enters the viewport.
 
void iconSizeChanged (const QSize &size)
 

Public Member Functions

 QHeaderView (Qt::Orientation orientation, QWidget *parent=nullptr)
 Creates a new generic header with the given orientation and parent.
 
virtual ~QHeaderView ()
 Destroys the header.
 
void setModel (QAbstractItemModel *model) override
 \reimp
 
Qt::Orientation orientation () const
 Returns the orientation of the header.
 
int offset () const
 Returns the offset of the header: this is the header's left-most (or top-most for vertical headers) visible pixel.
 
int length () const
 Returns the length along the orientation of the header.
 
QSize sizeHint () const override
 Returns a suitable size hint for this header.
 
void setVisible (bool v) override
 \reimp
 
int sectionSizeHint (int logicalIndex) const
 Returns a suitable size hint for the section specified by logicalIndex.
 
int visualIndexAt (int position) const
 Returns the visual index of the section that covers the given position in the viewport.
 
int logicalIndexAt (int position) const
 Returns the section that covers the given position in the viewport.
 
int logicalIndexAt (int x, int y) const
 Returns the logical index of the section at the given coordinate.
 
int logicalIndexAt (const QPoint &pos) const
 Returns the logical index of the section at the position given in pos.
 
int sectionSize (int logicalIndex) const
 Returns the width (or height for vertical headers) of the given logicalIndex.
 
int sectionPosition (int logicalIndex) const
 Returns the section position of the given logicalIndex, or -1 if the section is hidden.
 
int sectionViewportPosition (int logicalIndex) const
 Returns the section viewport position of the given logicalIndex.
 
void moveSection (int from, int to)
 Moves the section at visual index from to occupy visual index to.
 
void swapSections (int first, int second)
 Swaps the section at visual index first with the section at visual index second.
 
void resizeSection (int logicalIndex, int size)
 Resizes the section specified by logicalIndex to size measured in pixels.
 
void resizeSections (QHeaderView::ResizeMode mode)
 Resizes the sections according to the given mode, ignoring the current resize mode.
 
bool isSectionHidden (int logicalIndex) const
 Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise returns false.
 
void setSectionHidden (int logicalIndex, bool hide)
 If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown.
 
int hiddenSectionCount () const
 Returns the number of sections in the header that has been hidden.
 
void hideSection (int logicalIndex)
 Hides the section specified by logicalIndex.
 
void showSection (int logicalIndex)
 Shows the section specified by logicalIndex.
 
int count () const
 Returns the number of sections in the header.
 
int visualIndex (int logicalIndex) const
 Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
 
int logicalIndex (int visualIndex) const
 Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 or visualIndex >= QHeaderView::count().
 
void setSectionsMovable (bool movable)
 Sets \l sectionsMovable to movable.
 
bool sectionsMovable () const
 Returns \l sectionsMovable.
 
void setFirstSectionMovable (bool movable)
 
bool isFirstSectionMovable () const
 
void setSectionsClickable (bool clickable)
 Set \l sectionsClickable to clickable.
 
bool sectionsClickable () const
 Returns \l sectionsClickable.
 
void setHighlightSections (bool highlight)
 
bool highlightSections () const
 
ResizeMode sectionResizeMode (int logicalIndex) const
 
void setSectionResizeMode (ResizeMode mode)
 
void setSectionResizeMode (int logicalIndex, ResizeMode mode)
 
void setResizeContentsPrecision (int precision)
 
int resizeContentsPrecision () const
 
int stretchSectionCount () const
 Returns the number of sections that are set to resize mode stretch.
 
void setSortIndicatorShown (bool show)
 
bool isSortIndicatorShown () const
 
void setSortIndicator (int logicalIndex, Qt::SortOrder order)
 Sets the sort indicator for the section specified by the given logicalIndex in the direction specified by order, and removes the sort indicator from any other section that was showing it.
 
int sortIndicatorSection () const
 Returns the logical index of the section that has a sort indicator.
 
Qt::SortOrder sortIndicatorOrder () const
 Returns the order for the sort indicator.
 
void setSortIndicatorClearable (bool clearable)
 
bool isSortIndicatorClearable () const
 
bool stretchLastSection () const
 
void setStretchLastSection (bool stretch)
 
bool cascadingSectionResizes () const
 
void setCascadingSectionResizes (bool enable)
 
int defaultSectionSize () const
 
void setDefaultSectionSize (int size)
 
void resetDefaultSectionSize ()
 
int minimumSectionSize () const
 
void setMinimumSectionSize (int size)
 
int maximumSectionSize () const
 
void setMaximumSectionSize (int size)
 
Qt::Alignment defaultAlignment () const
 
void setDefaultAlignment (Qt::Alignment alignment)
 
void doItemsLayout () override
 
bool sectionsMoved () const
 Returns true if sections in the header has been moved; otherwise returns false;.
 
bool sectionsHidden () const
 Returns true if sections in the header has been hidden; otherwise returns false;.
 
QByteArray saveState () const
 Saves the current state of this header view.
 
bool restoreState (const QByteArray &state)
 Restores the state of this header view.
 
void reset () override
 \reimp
 
- Public Member Functions inherited from QAbstractItemView
 QAbstractItemView (QWidget *parent=nullptr)
 Constructs an abstract item view with the given parent.
 
 ~QAbstractItemView ()
 Destroys the view.
 
QAbstractItemModelmodel () const
 Returns the model that this view is presenting.
 
virtual void setSelectionModel (QItemSelectionModel *selectionModel)
 Sets the current selection model to the given selectionModel.
 
QItemSelectionModelselectionModel () const
 Returns the current selection model.
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 Sets the item delegate for this view and its model to delegate.
 
QAbstractItemDelegateitemDelegate () const
 Returns the item delegate used by this view and model.
 
void setSelectionMode (QAbstractItemView::SelectionMode mode)
 
QAbstractItemView::SelectionMode selectionMode () const
 
void setSelectionBehavior (QAbstractItemView::SelectionBehavior behavior)
 
QAbstractItemView::SelectionBehavior selectionBehavior () const
 
QModelIndex currentIndex () const
 Returns the model index of the current item.
 
QModelIndex rootIndex () const
 Returns the model index of the model's root item.
 
void setEditTriggers (EditTriggers triggers)
 
EditTriggers editTriggers () const
 
void setVerticalScrollMode (ScrollMode mode)
 
ScrollMode verticalScrollMode () const
 
void resetVerticalScrollMode ()
 
void setHorizontalScrollMode (ScrollMode mode)
 
ScrollMode horizontalScrollMode () const
 
void resetHorizontalScrollMode ()
 
void setAutoScroll (bool enable)
 
bool hasAutoScroll () const
 
void setAutoScrollMargin (int margin)
 
int autoScrollMargin () const
 
void setTabKeyNavigation (bool enable)
 
bool tabKeyNavigation () const
 
void setAlternatingRowColors (bool enable)
 
bool alternatingRowColors () const
 
void setIconSize (const QSize &size)
 
QSize iconSize () const
 
void setTextElideMode (Qt::TextElideMode mode)
 
Qt::TextElideMode textElideMode () const
 
virtual void keyboardSearch (const QString &search)
 Moves to and selects the item best matching the string search.
 
QSize sizeHintForIndex (const QModelIndex &index) const
 Returns the size hint for the item with the specified index or an invalid size for invalid indexes.
 
virtual int sizeHintForRow (int row) const
 Returns the height size hint for the specified row or -1 if there is no model.
 
virtual int sizeHintForColumn (int column) const
 Returns the width size hint for the specified column or -1 if there is no model.
 
uint32_t updateThreshold () const
 
void setUpdateThreshold (uint32_t threshold)
 
void openPersistentEditor (const QModelIndex &index)
 Opens a persistent editor on the item at the given index.
 
void closePersistentEditor (const QModelIndex &index)
 Closes the persistent editor for the item at the given index.
 
bool isPersistentEditorOpen (const QModelIndex &index) const
 
void setIndexWidget (const QModelIndex &index, QWidget *widget)
 Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.
 
QWidgetindexWidget (const QModelIndex &index) const
 Returns the widget for the item at the given index.
 
void setItemDelegateForRow (int row, QAbstractItemDelegate *delegate)
 Sets the given item delegate used by this view and model for the given row.
 
QAbstractItemDelegateitemDelegateForRow (int row) const
 Returns the item delegate used by this view and model for the given row, or \nullptr if no delegate has been assigned.
 
void setItemDelegateForColumn (int column, QAbstractItemDelegate *delegate)
 Sets the given item delegate used by this view and model for the given column.
 
QAbstractItemDelegateitemDelegateForColumn (int column) const
 Returns the item delegate used by this view and model for the given column.
 
virtual QAbstractItemDelegateitemDelegateForIndex (const QModelIndex &index) const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 \reimp
 

Protected Slots

void updateSection (int logicalIndex)
 
void resizeSections ()
 Resizes the sections according to their size hints.
 
void sectionsInserted (const QModelIndex &parent, int logicalFirst, int logicalLast)
 This slot is called when sections are inserted into the parent.
 
void sectionsAboutToBeRemoved (const QModelIndex &parent, int logicalFirst, int logicalLast)
 This slot is called when sections are removed from the parent.
 
- Protected Slots inherited from QAbstractItemView
virtual void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)
 This slot is called when rows are about to be removed.
 
virtual void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 This slot is called when the selection is changed.
 
virtual void updateEditorData ()
 
virtual void updateEditorGeometries ()
 
virtual void verticalScrollbarAction (int action)
 
virtual void horizontalScrollbarAction (int action)
 
virtual void verticalScrollbarValueChanged (int value)
 
virtual void horizontalScrollbarValueChanged (int value)
 
virtual void closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
 Closes the given editor, and releases it.
 
virtual void commitData (QWidget *editor)
 Commit the data in the editor to the model.
 
virtual void editorDestroyed (QObject *editor)
 This function is called when the given editor has been destroyed.
 

Protected Member Functions

 QHeaderView (QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent=nullptr)
 
void initialize ()
 
void initializeSections ()
 
void initializeSections (int start, int end)
 
void currentChanged (const QModelIndex &current, const QModelIndex &old) override
 \reimp
 
bool event (QEvent *e) override
 \reimp
 
void paintEvent (QPaintEvent *e) override
 \reimp
 
void mousePressEvent (QMouseEvent *e) override
 \reimp
 
void mouseMoveEvent (QMouseEvent *e) override
 \reimp
 
void mouseReleaseEvent (QMouseEvent *e) override
 \reimp
 
void mouseDoubleClickEvent (QMouseEvent *e) override
 \reimp
 
bool viewportEvent (QEvent *e) override
 \reimp
 
virtual void paintSection (QPainter *painter, const QRect &rect, int logicalIndex) const
 Paints the section specified by the given logicalIndex, using the given painter and rect.
 
virtual QSize sectionSizeFromContents (int logicalIndex) const
 Returns the size of the contents of the section specified by the given logicalIndex.
 
int horizontalOffset () const override
 Returns the horizontal offset of the header.
 
int verticalOffset () const override
 Returns the vertical offset of the header.
 
void updateGeometries () override
 \reimp
 
void scrollContentsBy (int dx, int dy) override
 \reimp
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >()) override
 \reimp
 
void rowsInserted (const QModelIndex &parent, int start, int end) override
 \reimp
 
QRect visualRect (const QModelIndex &index) const override
 \reimp
 
void scrollTo (const QModelIndex &index, ScrollHint hint) override
 \reimp
 
QModelIndex indexAt (const QPoint &p) const override
 \reimp
 
bool isIndexHidden (const QModelIndex &index) const override
 \reimp
 
QModelIndex moveCursor (CursorAction, Qt::KeyboardModifiers) override
 \reimp
 
void setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags flags) override
 \reimp
 
QRegion visualRegionForSelection (const QItemSelection &selection) const override
 
virtual void initStyleOptionForIndex (QStyleOptionHeader *option, int logicalIndex) const
 
virtual void initStyleOption (QStyleOptionHeader *option) const
 Initialize option with the values from this QHeaderView.
 
- Protected Member Functions inherited from QAbstractItemView
 QAbstractItemView (QAbstractItemViewPrivate &, QWidget *parent=nullptr)
 
virtual QModelIndexList selectedIndexes () const
 This convenience function returns a list of all selected and non-hidden item indexes in the view.
 
virtual bool edit (const QModelIndex &index, EditTrigger trigger, QEvent *event)
 Starts editing the item at index, creating an editor if necessary, and returns true if the view's \l{State} is now EditingState; otherwise returns false.
 
virtual QItemSelectionModel::SelectionFlags selectionCommand (const QModelIndex &index, const QEvent *event=nullptr) const
 Returns the SelectionFlags to be used when updating a selection model for the specified index.
 
virtual void initViewItemOption (QStyleOptionViewItem *option) const
 
State state () const
 Returns the item view's state.
 
void setState (State state)
 Sets the item view's state to the given state.
 
void scheduleDelayedItemsLayout ()
 Schedules a layout of the items in the view to be executed when the event processing starts.
 
void executeDelayedItemsLayout ()
 Executes the scheduled layouts without waiting for the event processing to begin.
 
void setDirtyRegion (const QRegion &region)
 Marks the given region as dirty and schedules it to be updated.
 
void scrollDirtyRegion (int dx, int dy)
 Prepares the view for scrolling by ({dx},{dy}) pixels by moving the dirty regions in the opposite direction.
 
QPoint dirtyRegionOffset () const
 Returns the offset of the dirty regions in the view.
 
void startAutoScroll ()
 
void stopAutoScroll ()
 
void doAutoScroll ()
 
bool focusNextPrevChild (bool next) override
 \reimp
 
bool event (QEvent *event) override
 \reimp
 
bool viewportEvent (QEvent *event) override
 This function is used to handle tool tips, and What's This? mode, if the given event is a QEvent::ToolTip,or a QEvent::WhatsThis.
 
void mousePressEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse button is pressed while the cursor is inside the widget.
 
void mouseMoveEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse move event is sent to the widget.
 
void mouseReleaseEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse button is released, after a mouse press event on the widget.
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse button is double clicked inside the widget.
 
void focusInEvent (QFocusEvent *event) override
 This function is called with the given event when the widget obtains the focus.
 
void focusOutEvent (QFocusEvent *event) override
 This function is called with the given event when the widget loses the focus.
 
void keyPressEvent (QKeyEvent *event) override
 This function is called with the given event when a key event is sent to the widget.
 
void resizeEvent (QResizeEvent *event) override
 This function is called with the given event when a resize event is sent to the widget.
 
void timerEvent (QTimerEvent *event) override
 This function is called with the given event when a timer event is sent to the widget.
 
void inputMethodEvent (QInputMethodEvent *event) override
 \reimp
 
bool eventFilter (QObject *object, QEvent *event) override
 \reimp
 
QSize viewportSizeHint () const override
 

Properties

bool firstSectionMovable
 Whether the first column can be moved by the user.
 
bool showSortIndicator
 whether the sort indicator is shown
 
bool sectionsMovable
 If sectionsMovable is true, the header sections may be moved by the user; otherwise they are fixed in place.
 
bool sectionsClickable
 Holds true if the header is clickable; otherwise false.
 
bool highlightSections
 whether the sections containing selected items are highlighted
 
bool stretchLastSection
 whether the last visible section in the header takes up all the available space
 
bool cascadingSectionResizes
 whether interactive resizing will be cascaded to the following sections once the section being resized by the user has reached its minimum size
 
int defaultSectionSize
 the default size of the header sections before resizing.
 
int minimumSectionSize
 the minimum size of the header sections.
 
int maximumSectionSize
 the maximum size of the header sections.
 
Qt::Alignment defaultAlignment
 the default alignment of the text in each header section
 
bool sortIndicatorClearable
 Whether the sort indicator can be cleared by clicking on a section multiple times.
 
- Properties inherited from QAbstractItemView
bool autoScroll
 whether autoscrolling in drag move events is enabled
 
int autoScrollMargin
 the size of the area when auto scrolling is triggered
 
EditTriggers editTriggers
 which actions will initiate item editing
 
bool tabKeyNavigation
 whether item navigation with tab and backtab is enabled.
 
bool alternatingRowColors
 whether to draw the background using alternating colors
 
SelectionMode selectionMode
 which selection mode the view operates in
 
SelectionBehavior selectionBehavior
 which selection behavior the view uses
 
QSize iconSize
 the size of items' icons
 
Qt::TextElideMode textElideMode
 the position of the "..." in elided text.
 
ScrollMode verticalScrollMode
 how the view scrolls its contents in the vertical direction
 
ScrollMode horizontalScrollMode
 how the view scrolls its contents in the horizontal direction
 
uint32_t updateThreshold
 

Private Member Functions

void initStyleOption (QStyleOptionFrame *option) const override
 

Friends

class QTableView
 
class QTreeView
 

Additional Inherited Members

- Protected Types inherited from QAbstractItemView
enum  CursorAction {
  MoveUp , MoveDown , MoveLeft , MoveRight ,
  MoveHome , MoveEnd , MovePageUp , MovePageDown ,
  MoveNext , MovePrevious
}
 This enum describes the different ways to navigate between items,. More...
 
enum  State {
  NoState , DraggingState , DragSelectingState , EditingState ,
  ExpandingState , CollapsingState , AnimatingState
}
 Describes the different states the view can be in. More...
 

Detailed Description

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

\inmodule QtWidgets

A QHeaderView displays the headers used in item views such as the QTableView and 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 QHeaderView class is one of the \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{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 orientation() and a number of sections, given by the 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 moveSection() and resizeSection(); they can also 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 visualIndex() 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.

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.

Definition at line 17 of file qheaderview.h.

Member Enumeration Documentation

◆ ResizeMode

The resize mode specifies the behavior of the header sections.

It can be set on the entire header view or on individual sections using setSectionResizeMode().

\value Interactive The user can resize the section. The section can also be resized programmatically using resizeSection(). The section size defaults to \l defaultSectionSize. (See also \l cascadingSectionResizes.)

\value Fixed The user cannot resize the section. The section can only be resized programmatically using resizeSection(). The section size defaults to \l defaultSectionSize.

\value Stretch QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically.

\value ResizeToContents 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: \value Custom Use Fixed instead.

See also
setSectionResizeMode(), stretchLastSection, minimumSectionSize
Enumerator
Interactive 
Stretch 
Fixed 
ResizeToContents 
Custom 

Definition at line 38 of file qheaderview.h.

Constructor & Destructor Documentation

◆ QHeaderView() [1/2]

QHeaderView::QHeaderView ( Qt::Orientation orientation,
QWidget * parent = nullptr )
explicit

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

Definition at line 284 of file qheaderview.cpp.

◆ ~QHeaderView()

QHeaderView::~QHeaderView ( )
virtual

Destroys the header.

Definition at line 308 of file qheaderview.cpp.

◆ QHeaderView() [2/2]

QHeaderView::QHeaderView ( QHeaderViewPrivate & dd,
Qt::Orientation orientation,
QWidget * parent = nullptr )
protected

Definition at line 295 of file qheaderview.cpp.

Member Function Documentation

◆ cascadingSectionResizes()

bool QHeaderView::cascadingSectionResizes ( ) const

Definition at line 1522 of file qheaderview.cpp.

◆ count()

int QHeaderView::count ( ) const

Returns the number of sections in the header.

See also
sectionCountChanged(), length()

Definition at line 1033 of file qheaderview.cpp.

◆ currentChanged()

void QHeaderView::currentChanged ( const QModelIndex & current,
const QModelIndex & old )
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 2426 of file qheaderview.cpp.

◆ dataChanged()

void QHeaderView::dataChanged ( const QModelIndex & topLeft,
const QModelIndex & bottomRight,
const QList< int > & roles = QList<int>() )
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 3194 of file qheaderview.cpp.

◆ defaultAlignment()

Qt::Alignment QHeaderView::defaultAlignment ( ) const

Definition at line 1682 of file qheaderview.cpp.

◆ defaultSectionSize()

int QHeaderView::defaultSectionSize ( ) const

Definition at line 1548 of file qheaderview.cpp.

◆ doItemsLayout()

void QHeaderView::doItemsLayout ( )
overridevirtual

Reimplemented from QAbstractItemView.

Definition at line 1701 of file qheaderview.cpp.

◆ event()

bool QHeaderView::event ( QEvent * e)
overrideprotected

\reimp

Definition at line 2452 of file qheaderview.cpp.

◆ geometriesChanged

void QHeaderView::geometriesChanged ( )
signal

This signal is emitted when the header's geometries have changed.

◆ headerDataChanged

void QHeaderView::headerDataChanged ( Qt::Orientation orientation,
int logicalFirst,
int logicalLast )
slot

Updates the changed header sections with the given orientation, from logicalFirst to logicalLast inclusive.

Definition at line 1849 of file qheaderview.cpp.

◆ hiddenSectionCount()

int QHeaderView::hiddenSectionCount ( ) const

Returns the number of sections in the header that has been hidden.

See also
setSectionHidden(), isSectionHidden()

Definition at line 973 of file qheaderview.cpp.

◆ hideSection()

void QHeaderView::hideSection ( int logicalIndex)
inline

Hides the section specified by logicalIndex.

See also
showSection(), isSectionHidden(), hiddenSectionCount(), setSectionHidden()

Definition at line 224 of file qheaderview.h.

◆ highlightSections()

bool QHeaderView::highlightSections ( ) const

Definition at line 1197 of file qheaderview.cpp.

◆ horizontalOffset()

int QHeaderView::horizontalOffset ( ) const
overrideprotectedvirtual

Returns the horizontal offset of the header.

This is 0 for vertical headers.

See also
offset()

Implements QAbstractItemView.

Definition at line 3143 of file qheaderview.cpp.

◆ indexAt()

QModelIndex QHeaderView::indexAt ( const QPoint & p) const
overrideprotectedvirtual

\reimp

Empty implementation because the header doesn't show QModelIndex items.

Implements QAbstractItemView.

Definition at line 3268 of file qheaderview.cpp.

◆ initialize()

void QHeaderView::initialize ( )
protected

Definition at line 317 of file qheaderview.cpp.

◆ initializeSections() [1/2]

void QHeaderView::initializeSections ( )
protected

Definition at line 2320 of file qheaderview.cpp.

◆ initializeSections() [2/2]

void QHeaderView::initializeSections ( int start,
int end )
protected

Definition at line 2354 of file qheaderview.cpp.

◆ initStyleOption() [1/2]

void QHeaderView::initStyleOption ( QStyleOptionFrame * option) const
overrideprivate

Definition at line 3529 of file qheaderview.cpp.

◆ initStyleOption() [2/2]

void QHeaderView::initStyleOption ( QStyleOptionHeader * option) const
protectedvirtual

Initialize option with the values from this QHeaderView.

This method is useful for subclasses when they need a QStyleOptionHeader, but do not want to fill in all the information themselves.

See also
QStyleOption::initFrom(), initStyleOptionForIndex()

Definition at line 3516 of file qheaderview.cpp.

◆ initStyleOptionForIndex()

void QHeaderView::initStyleOptionForIndex ( QStyleOptionHeader * option,
int logicalIndex ) const
protectedvirtual
Since
6.0

Initializes the style option from the specified logicalIndex. This function is called by the default implementation of paintSection after initStyleOption has been called.

See also
paintSection(), initStyleOption()

Definition at line 2961 of file qheaderview.cpp.

◆ isFirstSectionMovable()

bool QHeaderView::isFirstSectionMovable ( ) const

Definition at line 1158 of file qheaderview.cpp.

◆ isIndexHidden()

bool QHeaderView::isIndexHidden ( const QModelIndex & index) const
overrideprotectedvirtual

\reimp

Empty implementation because the header doesn't show QModelIndex items.

Implements QAbstractItemView.

Definition at line 3280 of file qheaderview.cpp.

◆ isSectionHidden()

bool QHeaderView::isSectionHidden ( int logicalIndex) const

Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise returns false.

See also
hideSection(), showSection(), setSectionHidden(), hiddenSectionCount()

Definition at line 953 of file qheaderview.cpp.

◆ isSortIndicatorClearable()

bool QHeaderView::isSortIndicatorClearable ( ) const

Definition at line 1463 of file qheaderview.cpp.

◆ isSortIndicatorShown()

bool QHeaderView::isSortIndicatorShown ( ) const

Definition at line 1359 of file qheaderview.cpp.

◆ length()

int QHeaderView::length ( ) const

Returns the length along the orientation of the header.

See also
sizeHint(), setSectionResizeMode(), offset()

Definition at line 470 of file qheaderview.cpp.

Referenced by testing.tools.encode_pdf_filter._PngIdatPdfStream::write().

+ Here is the caller graph for this function:

◆ logicalIndex()

int QHeaderView::logicalIndex ( int visualIndex) const

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.

See also
visualIndex(), sectionPosition()

Definition at line 1084 of file qheaderview.cpp.

◆ logicalIndexAt() [1/3]

int QHeaderView::logicalIndexAt ( const QPoint & pos) const
inline

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.

See also
sectionPosition()

Definition at line 222 of file qheaderview.h.

◆ logicalIndexAt() [2/3]

int QHeaderView::logicalIndexAt ( int position) const

Returns the section that covers the given position in the viewport.

See also
visualIndexAt(), isSectionHidden()

Definition at line 599 of file qheaderview.cpp.

◆ logicalIndexAt() [3/3]

int QHeaderView::logicalIndexAt ( int x,
int y ) const
inline

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.

Definition at line 220 of file qheaderview.h.

◆ maximumSectionSize()

int QHeaderView::maximumSectionSize ( ) const

Definition at line 1638 of file qheaderview.cpp.

◆ minimumSectionSize()

int QHeaderView::minimumSectionSize ( ) const

Definition at line 1586 of file qheaderview.cpp.

◆ mouseDoubleClickEvent()

void QHeaderView::mouseDoubleClickEvent ( QMouseEvent * e)
overrideprotected

\reimp

Definition at line 2846 of file qheaderview.cpp.

◆ mouseMoveEvent()

void QHeaderView::mouseMoveEvent ( QMouseEvent * e)
overrideprotected

\reimp

Definition at line 2655 of file qheaderview.cpp.

◆ mousePressEvent()

void QHeaderView::mousePressEvent ( QMouseEvent * e)
overrideprotected

\reimp

Definition at line 2610 of file qheaderview.cpp.

◆ mouseReleaseEvent()

void QHeaderView::mouseReleaseEvent ( QMouseEvent * e)
overrideprotected

\reimp

Definition at line 2773 of file qheaderview.cpp.

◆ moveCursor()

QModelIndex QHeaderView::moveCursor ( CursorAction ,
Qt::KeyboardModifiers  )
overrideprotectedvirtual

\reimp

Empty implementation because the header doesn't show QModelIndex items.

Implements QAbstractItemView.

Definition at line 3292 of file qheaderview.cpp.

◆ moveSection()

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

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

See also
sectionsMoved()

Definition at line 713 of file qheaderview.cpp.

◆ offset()

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

Definition at line 399 of file qheaderview.cpp.

Referenced by testing.tools.fixup_pdf_template.TemplateProcessor::insert_xref_entry(), and testing.tools.fixup_pdf_template.TemplateProcessor::process_line().

+ Here is the caller graph for this function:

◆ orientation()

Qt::Orientation QHeaderView::orientation ( ) const

Returns the orientation of the header.

See also
Qt::Orientation

Definition at line 386 of file qheaderview.cpp.

◆ paintEvent()

void QHeaderView::paintEvent ( QPaintEvent * e)
overrideprotected

\reimp

Definition at line 2504 of file qheaderview.cpp.

◆ paintSection()

void QHeaderView::paintSection ( QPainter * painter,
const QRect & rect,
int logicalIndex ) const
protectedvirtual

Paints the section specified by the given logicalIndex, using the given painter and rect.

Normally, you do not have to call this function.

Definition at line 3063 of file qheaderview.cpp.

◆ reset()

void QHeaderView::reset ( )
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 1834 of file qheaderview.cpp.

◆ resetDefaultSectionSize()

void QHeaderView::resetDefaultSectionSize ( )

Definition at line 1563 of file qheaderview.cpp.

◆ resizeContentsPrecision()

int QHeaderView::resizeContentsPrecision ( ) const
Since
5.2 Returns how precise QHeaderView will calculate on ResizeToContents.
See also
setResizeContentsPrecision(), setSectionResizeMode()

Definition at line 1313 of file qheaderview.cpp.

◆ resizeSection()

void QHeaderView::resizeSection ( int logicalIndex,
int size )

Resizes the section specified by logicalIndex to size measured in pixels.

The size parameter must be a value larger or equal to zero. A size equal to zero is however not recommended. In that situation hideSection should be used instead.

See also
sectionResized(), sectionSize(), hideSection()

Definition at line 841 of file qheaderview.cpp.

◆ resizeSections [1/2]

void QHeaderView::resizeSections ( )
protectedslot

Resizes the sections according to their size hints.

Normally, you do not have to call this function.

Definition at line 1902 of file qheaderview.cpp.

◆ resizeSections() [2/2]

void QHeaderView::resizeSections ( QHeaderView::ResizeMode mode)

Resizes the sections according to the given mode, ignoring the current resize mode.

See also
sectionResized()

Definition at line 924 of file qheaderview.cpp.

◆ restoreState()

bool QHeaderView::restoreState ( const QByteArray & state)

Restores the state of this header view.

This function returns true if the state was restored; otherwise returns false.

See also
saveState()

Definition at line 1800 of file qheaderview.cpp.

◆ rowsInserted()

void QHeaderView::rowsInserted ( const QModelIndex & parent,
int start,
int end )
overrideprotectedvirtual

\reimp

Empty implementation because the header doesn't show QModelIndex items.

Reimplemented from QAbstractItemView.

Definition at line 3232 of file qheaderview.cpp.

◆ saveState()

QByteArray QHeaderView::saveState ( ) const

Saves the current state of this header view.

To restore the saved state, pass the return value to restoreState().

See also
restoreState()

Definition at line 1781 of file qheaderview.cpp.

◆ scrollContentsBy()

void QHeaderView::scrollContentsBy ( int dx,
int dy )
overrideprotected

\reimp

Definition at line 3184 of file qheaderview.cpp.

◆ scrollTo()

void QHeaderView::scrollTo ( const QModelIndex & index,
ScrollHint hint )
overrideprotectedvirtual

\reimp

Empty implementation because the header doesn't show QModelIndex items.

Implements QAbstractItemView.

Definition at line 3256 of file qheaderview.cpp.

◆ sectionClicked

void QHeaderView::sectionClicked ( int logicalIndex)
signal

This signal is emitted when a section is clicked.

The section's logical index is specified by logicalIndex.

Note that the sectionPressed signal will also be emitted.

See also
setSectionsClickable(), sectionPressed()

◆ sectionCountChanged

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.

See also
count(), length(), headerDataChanged()

◆ sectionDoubleClicked

void QHeaderView::sectionDoubleClicked ( int logicalIndex)
signal

This signal is emitted when a section is double-clicked.

The section's logical index is specified by logicalIndex.

See also
setSectionsClickable()

◆ sectionEntered

void QHeaderView::sectionEntered ( int logicalIndex)
signal

This signal is emitted when the cursor moves over the section and the left mouse button is pressed.

The section's logical index is specified by logicalIndex.

See also
setSectionsClickable(), sectionPressed()

◆ sectionHandleDoubleClicked

void QHeaderView::sectionHandleDoubleClicked ( int logicalIndex)
signal

This signal is emitted when a section is double-clicked.

The section's logical index is specified by logicalIndex.

See also
setSectionsClickable()

◆ sectionMoved

void QHeaderView::sectionMoved ( int logicalIndex,
int oldVisualIndex,
int newVisualIndex )
signal

This signal is emitted when a section is moved.

The section's logical index is specified by logicalIndex, the old index by oldVisualIndex, and the new index position by newVisualIndex.

See also
moveSection()

◆ sectionPosition()

int QHeaderView::sectionPosition ( int logicalIndex) const

Returns the section position of the given logicalIndex, or -1 if the section is hidden.

The position is measured in pixels from the first visible item's top-left corner to the top-left corner of the item with logicalIndex. The measurement is along the x-axis for horizontal headers and along the y-axis for vertical headers.

See also
sectionViewportPosition()

Definition at line 639 of file qheaderview.cpp.

◆ sectionPressed

void QHeaderView::sectionPressed ( int logicalIndex)
signal

This signal is emitted when a section is pressed.

The section's logical index is specified by logicalIndex.

See also
setSectionsClickable()

◆ sectionResized

void QHeaderView::sectionResized ( int logicalIndex,
int oldSize,
int newSize )
signal

This signal is emitted when a section is resized.

The section's logical number is specified by logicalIndex, the old size by oldSize, and the new size by newSize.

See also
resizeSection()

◆ sectionResizeMode()

QHeaderView::ResizeMode QHeaderView::sectionResizeMode ( int logicalIndex) const
Since
5.0

Returns the resize mode that applies to the section specified by the given logicalIndex.

See also
setSectionResizeMode()

Definition at line 1268 of file qheaderview.cpp.

◆ sectionsAboutToBeRemoved

void QHeaderView::sectionsAboutToBeRemoved ( const QModelIndex & parent,
int logicalFirst,
int logicalLast )
protectedslot

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.

Definition at line 2029 of file qheaderview.cpp.

◆ sectionsClickable()

bool QHeaderView::sectionsClickable ( ) const

Returns \l sectionsClickable.

Definition at line 1185 of file qheaderview.cpp.

◆ sectionsHidden()

bool QHeaderView::sectionsHidden ( ) const

Returns true if sections in the header has been hidden; otherwise returns false;.

See also
setSectionHidden()

Definition at line 1725 of file qheaderview.cpp.

◆ sectionsInserted

void QHeaderView::sectionsInserted ( const QModelIndex & parent,
int logicalFirst,
int logicalLast )
protectedslot

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.

Definition at line 1918 of file qheaderview.cpp.

◆ sectionSize()

int QHeaderView::sectionSize ( int logicalIndex) const

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

See also
length(), setSectionResizeMode(), defaultSectionSize()

Definition at line 614 of file qheaderview.cpp.

◆ sectionSizeFromContents()

QSize QHeaderView::sectionSizeFromContents ( int logicalIndex) const
protectedvirtual

Returns the size of the contents of the section specified by the given logicalIndex.

See also
defaultSectionSize()

Definition at line 3100 of file qheaderview.cpp.

◆ sectionSizeHint()

int QHeaderView::sectionSizeHint ( int logicalIndex) const

Returns a suitable size hint for the section specified by logicalIndex.

See also
sizeHint(), defaultSectionSize(), minimumSectionSize(), maximumSectionSize() Qt::SizeHintRole

Definition at line 537 of file qheaderview.cpp.

◆ sectionsMovable()

bool QHeaderView::sectionsMovable ( ) const

Returns \l sectionsMovable.

Definition at line 1122 of file qheaderview.cpp.

◆ sectionsMoved()

bool QHeaderView::sectionsMoved ( ) const

Returns true if sections in the header has been moved; otherwise returns false;.

See also
moveSection()

Definition at line 1713 of file qheaderview.cpp.

◆ sectionViewportPosition()

int QHeaderView::sectionViewportPosition ( int logicalIndex) const

Returns the section viewport position of the given logicalIndex.

If the section is hidden, the return value is undefined.

See also
sectionPosition(), isSectionHidden()

Definition at line 659 of file qheaderview.cpp.

◆ setCascadingSectionResizes()

void QHeaderView::setCascadingSectionResizes ( bool enable)

Definition at line 1528 of file qheaderview.cpp.

◆ setDefaultAlignment()

void QHeaderView::setDefaultAlignment ( Qt::Alignment alignment)

Definition at line 1688 of file qheaderview.cpp.

◆ setDefaultSectionSize()

void QHeaderView::setDefaultSectionSize ( int size)

Definition at line 1554 of file qheaderview.cpp.

◆ setFirstSectionMovable()

void QHeaderView::setFirstSectionMovable ( bool movable)

Definition at line 1152 of file qheaderview.cpp.

◆ setHighlightSections()

void QHeaderView::setHighlightSections ( bool highlight)

Definition at line 1191 of file qheaderview.cpp.

◆ setMaximumSectionSize()

void QHeaderView::setMaximumSectionSize ( int size)

Definition at line 1646 of file qheaderview.cpp.

◆ setMinimumSectionSize()

void QHeaderView::setMinimumSectionSize ( int size)

Definition at line 1598 of file qheaderview.cpp.

◆ setModel()

void QHeaderView::setModel ( QAbstractItemModel * model)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 333 of file qheaderview.cpp.

◆ setOffset

void QHeaderView::setOffset ( int offset)
slot

Sets the header's offset to offset.

See also
offset(), length()

Definition at line 413 of file qheaderview.cpp.

◆ setOffsetToLastSection

void QHeaderView::setOffsetToLastSection ( )
slot

Sets the offset to make the last section visible.

See also
setOffset(), sectionPosition(), setOffsetToSectionPosition()

Definition at line 456 of file qheaderview.cpp.

◆ setOffsetToSectionPosition

void QHeaderView::setOffsetToSectionPosition ( int visualSectionNumber)
slot

Sets the offset to the start of the section at the given visualSectionNumber.

visualSectionNumber is the actual visible section when hiddenSections are not considered. That is not always the same as visualIndex().

See also
setOffset(), sectionPosition()

Definition at line 442 of file qheaderview.cpp.

◆ setResizeContentsPrecision()

void QHeaderView::setResizeContentsPrecision ( int precision)
Since
5.2 Sets how precise QHeaderView should calculate the size when ResizeToContents is used. A low value will provide a less accurate but fast auto resize while a higher value will provide a more accurate resize that however can be slow.

The number precision specifies how many sections that should be consider when calculating the preferred size.

The default value is 1000 meaning that a horizontal column with auto-resize will look at maximum 1000 rows on calculating when doing an auto resize.

Special value 0 means that it will look at only the visible area. Special value -1 will imply looking at all elements.

This value is used in QTableView::sizeHintForColumn(), QTableView::sizeHintForRow() and QTreeView::sizeHintForColumn(). Reimplementing these functions can make this function not having an effect.

See also
resizeContentsPrecision(), setSectionResizeMode(), resizeSections(), QTableView::sizeHintForColumn(), QTableView::sizeHintForRow(), QTreeView::sizeHintForColumn()

Definition at line 1299 of file qheaderview.cpp.

◆ setSectionHidden()

void QHeaderView::setSectionHidden ( int logicalIndex,
bool hide )

If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown.

See also
isSectionHidden(), hiddenSectionCount()

Definition at line 986 of file qheaderview.cpp.

◆ setSectionResizeMode() [1/2]

void QHeaderView::setSectionResizeMode ( int logicalIndex,
ResizeMode mode )
Since
5.0

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 stretchLastSection property is set to true. This is the default for the horizontal headers provided by QTreeView.
See also
setStretchLastSection(), resizeContentsPrecision()

Definition at line 1237 of file qheaderview.cpp.

◆ setSectionResizeMode() [2/2]

void QHeaderView::setSectionResizeMode ( ResizeMode mode)
Since
5.0

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

See also
length(), sectionResized()

Definition at line 1212 of file qheaderview.cpp.

◆ setSectionsClickable()

void QHeaderView::setSectionsClickable ( bool clickable)

Set \l sectionsClickable to clickable.

Definition at line 1176 of file qheaderview.cpp.

◆ setSectionsMovable()

void QHeaderView::setSectionsMovable ( bool movable)

Sets \l sectionsMovable to movable.

Definition at line 1113 of file qheaderview.cpp.

◆ setSelection()

void QHeaderView::setSelection ( const QRect & rect,
QItemSelectionModel::SelectionFlags flags )
overrideprotectedvirtual

\reimp

Selects the items in the given rect according to the specified flags.

The base class implementation does nothing.

Implements QAbstractItemView.

Definition at line 3306 of file qheaderview.cpp.

◆ setSortIndicator()

void QHeaderView::setSortIndicator ( int logicalIndex,
Qt::SortOrder order )

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

logicalIndex may be -1, in which case no sort indicator will be shown and the model will return to its natural, unsorted order. Note that not all models support this and may even crash in this case.

See also
sortIndicatorSection(), sortIndicatorOrder()

Definition at line 1377 of file qheaderview.cpp.

◆ setSortIndicatorClearable()

void QHeaderView::setSortIndicatorClearable ( bool clearable)

Definition at line 1454 of file qheaderview.cpp.

◆ setSortIndicatorShown()

void QHeaderView::setSortIndicatorShown ( bool show)

Definition at line 1342 of file qheaderview.cpp.

◆ setStretchLastSection()

void QHeaderView::setStretchLastSection ( bool stretch)

Definition at line 1490 of file qheaderview.cpp.

◆ setVisible()

void QHeaderView::setVisible ( bool v)
override

\reimp

Definition at line 518 of file qheaderview.cpp.

◆ showSection()

void QHeaderView::showSection ( int logicalIndex)
inline

Shows the section specified by logicalIndex.

See also
hideSection(), isSectionHidden(), hiddenSectionCount(), setSectionHidden()

Definition at line 226 of file qheaderview.h.

◆ sizeHint()

QSize QHeaderView::sizeHint ( ) const
override

Returns a suitable size hint for this header.

See also
sectionSizeHint()

Definition at line 485 of file qheaderview.cpp.

◆ sortIndicatorChanged

void QHeaderView::sortIndicatorChanged ( int logicalIndex,
Qt::SortOrder order )
signal

This signal is emitted when the section containing the sort indicator or the order indicated is changed.

The section's logical index is specified by logicalIndex and the sort order is specified by order.

See also
setSortIndicator()

◆ sortIndicatorClearableChanged

void QHeaderView::sortIndicatorClearableChanged ( bool clearable)
signal

◆ sortIndicatorOrder()

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(), sortIndicatorSection()

Definition at line 1428 of file qheaderview.cpp.

◆ sortIndicatorSection()

int QHeaderView::sortIndicatorSection ( ) const

Returns the logical index of the section that has a sort indicator.

By default this is section 0.

See also
setSortIndicator(), sortIndicatorOrder(), setSortIndicatorShown()

Definition at line 1415 of file qheaderview.cpp.

◆ stretchLastSection()

bool QHeaderView::stretchLastSection ( ) const

Definition at line 1484 of file qheaderview.cpp.

◆ stretchSectionCount()

int QHeaderView::stretchSectionCount ( ) const

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.

See also
stretchLastSection

Definition at line 1327 of file qheaderview.cpp.

◆ swapSections()

void QHeaderView::swapSections ( int first,
int second )

Swaps the section at visual index first with the section at visual index second.

See also
moveSection()

Definition at line 777 of file qheaderview.cpp.

◆ updateGeometries()

void QHeaderView::updateGeometries ( )
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 3171 of file qheaderview.cpp.

◆ updateSection

void QHeaderView::updateSection ( int logicalIndex)
protectedslot

Updates the section specified by the given logicalIndex.

Definition at line 1886 of file qheaderview.cpp.

◆ verticalOffset()

int QHeaderView::verticalOffset ( ) const
overrideprotectedvirtual

Returns the vertical offset of the header.

This is 0 for horizontal headers.

See also
offset()

Implements QAbstractItemView.

Definition at line 3158 of file qheaderview.cpp.

◆ viewportEvent()

bool QHeaderView::viewportEvent ( QEvent * e)
overrideprotected

\reimp

Definition at line 2872 of file qheaderview.cpp.

◆ visualIndex()

int QHeaderView::visualIndex ( int logicalIndex) const

Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.

Hidden sections still have valid visual indexes.

See also
logicalIndex()

Definition at line 1051 of file qheaderview.cpp.

◆ visualIndexAt()

int QHeaderView::visualIndexAt ( int position) const

Returns the visual index of the section that covers the given position in the viewport.

See also
logicalIndexAt()

Definition at line 561 of file qheaderview.cpp.

◆ visualRect()

QRect QHeaderView::visualRect ( const QModelIndex & index) const
overrideprotectedvirtual

\reimp

Empty implementation because the header doesn't show QModelIndex items.

Implements QAbstractItemView.

Definition at line 3244 of file qheaderview.cpp.

◆ visualRegionForSelection()

QRegion QHeaderView::visualRegionForSelection ( const QItemSelection & selection) const
overrideprotectedvirtual

Implements QAbstractItemView.

Definition at line 3315 of file qheaderview.cpp.

Friends And Related Symbol Documentation

◆ QTableView

friend class QTableView
friend

Definition at line 210 of file qheaderview.h.

◆ QTreeView

friend class QTreeView
friend

Definition at line 211 of file qheaderview.h.

Property Documentation

◆ cascadingSectionResizes

bool QHeaderView::cascadingSectionResizes
readwrite

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 \l Interactive as their resize mode.

The default value is false.

See also
setSectionResizeMode()

Definition at line 26 of file qheaderview.h.

◆ defaultAlignment

Qt::Alignment QHeaderView::defaultAlignment
readwrite

the default alignment of the text in each header section

Definition at line 32 of file qheaderview.h.

◆ defaultSectionSize

int QHeaderView::defaultSectionSize
readwrite

the default size of the header sections before resizing.

This property only affects sections that have \l Interactive or \l Fixed as their resize mode.

By default, the value of this property is style dependent. Thus, when the style changes, this property updates from it. Calling setDefaultSectionSize() stops the updates, calling resetDefaultSectionSize() will restore default behavior.

See also
setSectionResizeMode(), minimumSectionSize

Definition at line 28 of file qheaderview.h.

◆ firstSectionMovable

bool QHeaderView::firstSectionMovable
readwrite

Whether the first column can be moved by the user.

This property controls whether the first column can be moved by the user. In a QTreeView, the first column holds the tree structure and is therefore non-movable by default, even after setSectionsMovable(true).

It can be made movable again, for instance in the case of flat lists without a tree structure, by calling this method. In such a scenario, it is recommended to call QTreeView::setRootIsDecorated(false) as well.

treeView->setRootIsDecorated(false);
treeView->header()->setFirstSectionMovable(true);

Setting it to true has no effect unless setSectionsMovable(true) is called as well.

See also
setSectionsMovable()
Since
5.11

Definition at line 20 of file qheaderview.h.

◆ highlightSections

bool QHeaderView::highlightSections
readwrite

whether the sections containing selected items are highlighted

By default, this property is false.

Definition at line 24 of file qheaderview.h.

◆ maximumSectionSize

int QHeaderView::maximumSectionSize
readwrite

the maximum size of the header sections.

Since
5.2

The maximum section size is the largest section size allowed. The default value for this property is 1048575, which is also the largest possible size for a section. Setting maximum to -1 will reset the value to the largest section size.

With exception of stretch this property is honored by all \l{ResizeMode}{resize modes}

See also
setSectionResizeMode(), defaultSectionSize

Definition at line 31 of file qheaderview.h.

◆ minimumSectionSize

int QHeaderView::minimumSectionSize
readwrite

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, QHeaderView will use the \l{fontMetrics()}{font metrics} size.

This property is honored by all \l{ResizeMode}{resize modes}.

See also
setSectionResizeMode(), defaultSectionSize

Definition at line 30 of file qheaderview.h.

◆ sectionsClickable

bool QHeaderView::sectionsClickable
readwrite

Holds true if the header is clickable; otherwise 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
sectionPressed(), setSortIndicatorShown()

Definition at line 23 of file qheaderview.h.

◆ sectionsMovable

bool QHeaderView::sectionsMovable
readwrite

If sectionsMovable is true, the header sections may be moved by the user; otherwise they are fixed in place.

When used in combination with QTreeView, the first column is not movable (since it contains the tree structure), by default. You can make it movable with setFirstSectionMovable(true).

See also
sectionMoved()
setFirstSectionMovable()

Definition at line 22 of file qheaderview.h.

◆ showSortIndicator

bool QHeaderView::showSortIndicator
readwrite

whether the sort indicator is shown

By default, this property is false.

See also
setSectionsClickable()

Definition at line 21 of file qheaderview.h.

◆ sortIndicatorClearable

bool QHeaderView::sortIndicatorClearable
readwrite

Whether the sort indicator can be cleared by clicking on a section multiple times.

Since
6.1

This property controls whether the user is able to remove the sorting indicator on a given section by clicking on the section multiple times. Normally, clicking on a section will simply change the sorting order for that section. By setting this property to true, the sorting indicator will be cleared after alternating to ascending and descending; this will typically restore the original sorting of a model.

Setting this property to true has no effect unless sectionsClickable() is also true (which is the default for certain views, for instance QTableView, or is automatically set when making a view sortable, for instance by calling QTreeView::setSortingEnabled).

Definition at line 33 of file qheaderview.h.

◆ stretchLastSection

bool QHeaderView::stretchLastSection
readwrite

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 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.
See also
setSectionResizeMode()

Definition at line 25 of file qheaderview.h.


The documentation for this class was generated from the following files: