Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Slots | Protected Functions | Properties | List of all members
QHeaderView Class Reference

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

#include <qheaderview.h>

Inheritance diagram for QHeaderView:
QAbstractItemView QAbstractScrollArea QFrame QWidget QObject QPaintDevice

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  DragDropMode {
  NoDragDrop, DragOnly, DropOnly, DragDrop,
  InternalMove
}
 Describes the various drag and drop events the view can act upon. 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  ScrollHint { EnsureVisible, PositionAtTop, PositionAtBottom, PositionAtCenter }
 
enum  ScrollMode { ScrollPerItem, ScrollPerPixel }
 
enum  SelectionBehavior { SelectItems, SelectRows, SelectColumns }
 
enum  SelectionMode {
  NoSelection, SingleSelection, MultiSelection, ExtendedSelection,
  ContiguousSelection
}
 This enum indicates how the view responds to user selections: More...
 
- Public Types inherited from QFrame
enum  Shadow { Plain = 0x0010, Raised = 0x0020, Sunken = 0x0030 }
 This enum type defines the types of shadow that are used to give a 3D effect to frames. More...
 
enum  Shape {
  NoFrame = 0, Box = 0x0001, Panel = 0x0002, WinPanel = 0x0003,
  HLine = 0x0004, VLine = 0x0005, StyledPanel = 0x0006
}
 This enum type defines the shapes of frame available. More...
 
enum  StyleMask { Shadow_Mask = 0x00f0, Shape_Mask = 0x000f }
 This enum defines two constants that can be used to extract the two components of frameStyle(): More...
 
- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Slots

void headerDataChanged (Qt::Orientation orientation, int logicalFirst, int logicalLast)
 Updates the changed header sections with the given orientation, from logicalFirst to logicalLast inclusive. More...
 
void setOffset (int offset)
 Sets the header's offset to offset. More...
 
void setOffsetToLastSection ()
 Sets the offset to make the last section visible. More...
 
void setOffsetToSectionPosition (int visualIndex)
 Sets the offset to the start of the section at the given visualIndex. More...
 
- Public Slots inherited from QAbstractItemView
void clearSelection ()
 Deselects all selected items. More...
 
void edit (const QModelIndex &index)
 Starts editing the item corresponding to the given index if it is editable. More...
 
void scrollToBottom ()
 Scrolls the view to the bottom. More...
 
void scrollToTop ()
 Scrolls the view to the top. More...
 
virtual void selectAll ()
 Selects all items in the view. More...
 
void setCurrentIndex (const QModelIndex &index)
 Sets the current item to be the item at index. More...
 
virtual void setRootIndex (const QModelIndex &index)
 Sets the root item to the item at the given index. More...
 
void update (const QModelIndex &index)
 Updates the area occupied by the given index. More...
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void geometriesChanged ()
 This signal is emitted when the header's geometries have changed. More...
 
void sectionAutoResize (int logicalIndex, QHeaderView::ResizeMode mode)
 
void sectionClicked (int logicalIndex)
 This signal is emitted when a section is clicked. More...
 
void sectionCountChanged (int oldCount, int newCount)
 This signal is emitted when the number of sections changes, i. More...
 
void sectionDoubleClicked (int logicalIndex)
 This signal is emitted when a section is double-clicked. More...
 
void sectionEntered (int logicalIndex)
 This signal is emitted when the cursor moves over the section and the left mouse button is pressed. More...
 
void sectionHandleDoubleClicked (int logicalIndex)
 This signal is emitted when a section is double-clicked. More...
 
void sectionMoved (int logicalIndex, int oldVisualIndex, int newVisualIndex)
 This signal is emitted when a section is moved. More...
 
void sectionPressed (int logicalIndex)
 This signal is emitted when a section is pressed. More...
 
void sectionResized (int logicalIndex, int oldSize, int newSize)
 This signal is emitted when a section is resized. More...
 
void sortIndicatorChanged (int logicalIndex, Qt::SortOrder order)
 
- Signals inherited from QAbstractItemView
void activated (const QModelIndex &index)
 This signal is emitted when the item specified by index is activated by the user. More...
 
void clicked (const QModelIndex &index)
 This signal is emitted when a mouse button is clicked. More...
 
void doubleClicked (const QModelIndex &index)
 This signal is emitted when a mouse button is double-clicked. More...
 
void entered (const QModelIndex &index)
 This signal is emitted when the mouse cursor enters the item specified by index. More...
 
void pressed (const QModelIndex &index)
 This signal is emitted when a mouse button is pressed. More...
 
void viewportEntered ()
 This signal is emitted when the mouse cursor enters the viewport. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

bool cascadingSectionResizes () const
 
int count () const
 Returns the number of sections in the header. More...
 
Qt::Alignment defaultAlignment () const
 
int defaultSectionSize () const
 
void doItemsLayout ()
 
int hiddenSectionCount () const
 Returns the number of sections in the header that has been hidden. More...
 
void hideSection (int logicalIndex)
 Hides the section specified by logicalIndex. More...
 
bool highlightSections () const
 
bool isClickable () const
 Returns true if the header is clickable; otherwise returns false. More...
 
bool isMovable () const
 Returns true if the header can be moved by the user; otherwise returns false. More...
 
bool isSectionHidden (int logicalIndex) const
 Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise returns false. More...
 
bool isSortIndicatorShown () const
 
int length () const
 Returns the length along the orientation of the header. More...
 
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(). More...
 
int logicalIndexAt (int position) const
 Returns the section that covers the given position in the viewport. More...
 
int logicalIndexAt (int x, int y) const
 Returns the logical index of the section at the given coordinate. More...
 
int logicalIndexAt (const QPoint &pos) const
 Returns the logical index of the section at the position given in pos. More...
 
int minimumSectionSize () const
 
void moveSection (int from, int to)
 Moves the section at visual index from to occupy visual index to. More...
 
int offset () const
 Returns the offset of the header: this is the header's left-most (or top-most for vertical headers) visible pixel. More...
 
Qt::Orientation orientation () const
 Returns the orientation of the header. More...
 
 QHeaderView (Qt::Orientation orientation, QWidget *parent=0)
 Creates a new generic header with the given orientation and parent. More...
 
void reset ()
 Reimplemented Function More...
 
ResizeMode resizeMode (int logicalIndex) const
 Returns the resize mode that applies to the section specified by the given logicalIndex. More...
 
void resizeSection (int logicalIndex, int size)
 Resizes the section specified by logicalIndex to size measured in pixels. More...
 
void resizeSections (QHeaderView::ResizeMode mode)
 Resizes the sections according to the given mode, ignoring the current resize mode. More...
 
bool restoreState (const QByteArray &state)
 Restores the state of this header view. More...
 
QByteArray saveState () const
 Saves the current state of this header view. More...
 
int sectionPosition (int logicalIndex) const
 Returns the section position of the given logicalIndex, or -1 if the section is hidden. More...
 
bool sectionsHidden () const
 
int sectionSize (int logicalIndex) const
 Returns the width (or height for vertical headers) of the given logicalIndex. More...
 
int sectionSizeHint (int logicalIndex) const
 Returns a suitable size hint for the section specified by logicalIndex. More...
 
bool sectionsMoved () const
 Returns true if sections in the header has been moved; otherwise returns false;. More...
 
int sectionViewportPosition (int logicalIndex) const
 Returns the section viewport position of the given logicalIndex. More...
 
void setCascadingSectionResizes (bool enable)
 
void setClickable (bool clickable)
 If clickable is true, the header will respond to single clicks. More...
 
void setDefaultAlignment (Qt::Alignment alignment)
 
void setDefaultSectionSize (int size)
 
void setHighlightSections (bool highlight)
 
void setMinimumSectionSize (int size)
 
void setModel (QAbstractItemModel *model)
 Reimplemented Function More...
 
void setMovable (bool movable)
 If movable is true, the header may be moved by the user; otherwise it is fixed in place. More...
 
void setResizeMode (ResizeMode mode)
 Sets the constraints on how the header can be resized to those described by the given mode. More...
 
void setResizeMode (int logicalIndex, ResizeMode mode)
 Sets the constraints on how the section specified by logicalIndex in the header can be resized to those described by the given mode. More...
 
void setSectionHidden (int logicalIndex, bool hide)
 If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown. More...
 
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. More...
 
void setSortIndicatorShown (bool show)
 
void setStretchLastSection (bool stretch)
 
void showSection (int logicalIndex)
 Shows the section specified by logicalIndex. More...
 
QSize sizeHint () const
 Returns a suitable size hint for this header. More...
 
Qt::SortOrder sortIndicatorOrder () const
 Returns the order for the sort indicator. More...
 
int sortIndicatorSection () const
 Returns the logical index of the section that has a sort indicator. More...
 
bool stretchLastSection () const
 
int stretchSectionCount () const
 Returns the number of sections that are set to resize mode stretch. More...
 
void swapSections (int first, int second)
 Swaps the section at visual index first with the section at visual index second. More...
 
int visualIndex (int logicalIndex) const
 Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise. More...
 
int visualIndexAt (int position) const
 Returns the visual index of the section that covers the given position in the viewport. More...
 
virtual ~QHeaderView ()
 Destroys the header. More...
 
- Public Functions inherited from QAbstractItemView
bool alternatingRowColors () const
 
int autoScrollMargin () const
 
void closePersistentEditor (const QModelIndex &index)
 Closes the persistent editor for the item at the given index. More...
 
QModelIndex currentIndex () const
 Returns the model index of the current item. More...
 
Qt::DropAction defaultDropAction () const
 
DragDropMode dragDropMode () const
 
bool dragDropOverwriteMode () const
 
bool dragEnabled () const
 
EditTriggers editTriggers () const
 
bool hasAutoScroll () const
 
ScrollMode horizontalScrollMode () const
 
QSize iconSize () const
 
QWidgetindexWidget (const QModelIndex &index) const
 Returns the widget for the item at the given index. More...
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 Reimplemented Function More...
 
QAbstractItemDelegateitemDelegate () const
 Returns the item delegate used by this view and model. More...
 
QAbstractItemDelegateitemDelegate (const QModelIndex &index) const
 Returns the item delegate used by this view and model for the given index. More...
 
QAbstractItemDelegateitemDelegateForColumn (int column) const
 Returns the item delegate used by this view and model for the given column. More...
 
QAbstractItemDelegateitemDelegateForRow (int row) const
 Returns the item delegate used by this view and model for the given row, or 0 if no delegate has been assigned. More...
 
virtual void keyboardSearch (const QString &search)
 Moves to and selects the item best matching the string search. More...
 
QAbstractItemModelmodel () const
 Returns the model that this view is presenting. More...
 
void openPersistentEditor (const QModelIndex &index)
 Opens a persistent editor on the item at the given index. More...
 
 QAbstractItemView (QWidget *parent=0)
 Constructs an abstract item view with the given parent. More...
 
QModelIndex rootIndex () const
 Returns the model index of the model's root item. More...
 
QAbstractItemView::SelectionBehavior selectionBehavior () const
 
QAbstractItemView::SelectionMode selectionMode () const
 
QItemSelectionModelselectionModel () const
 Returns the current selection model. More...
 
void setAlternatingRowColors (bool enable)
 
void setAutoScroll (bool enable)
 
void setAutoScrollMargin (int margin)
 
void setDefaultDropAction (Qt::DropAction dropAction)
 
void setDragDropMode (DragDropMode behavior)
 
void setDragDropOverwriteMode (bool overwrite)
 
void setDragEnabled (bool enable)
 
void setDropIndicatorShown (bool enable)
 
void setEditTriggers (EditTriggers triggers)
 
void setHorizontalScrollMode (ScrollMode mode)
 
void setIconSize (const QSize &size)
 
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. More...
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 Sets the item delegate for this view and its model to delegate. More...
 
void setItemDelegateForColumn (int column, QAbstractItemDelegate *delegate)
 Sets the given item delegate used by this view and model for the given column. More...
 
void setItemDelegateForRow (int row, QAbstractItemDelegate *delegate)
 Sets the given item delegate used by this view and model for the given row. More...
 
void setSelectionBehavior (QAbstractItemView::SelectionBehavior behavior)
 
void setSelectionMode (QAbstractItemView::SelectionMode mode)
 
virtual void setSelectionModel (QItemSelectionModel *selectionModel)
 Sets the current selection model to the given selectionModel. More...
 
void setTabKeyNavigation (bool enable)
 
void setTextElideMode (Qt::TextElideMode mode)
 
void setVerticalScrollMode (ScrollMode mode)
 
bool showDropIndicator () const
 
virtual int sizeHintForColumn (int column) const
 Returns the width size hint for the specified column or -1 if there is no model. More...
 
QSize sizeHintForIndex (const QModelIndex &index) const
 Returns the size hint for the item with the specified index or an invalid size for invalid indexes. More...
 
virtual int sizeHintForRow (int row) const
 Returns the height size hint for the specified row or -1 if there is no model. More...
 
bool tabKeyNavigation () const
 
Qt::TextElideMode textElideMode () const
 
ScrollMode verticalScrollMode () const
 
 ~QAbstractItemView ()
 Destroys the view. More...
 
- Public Functions inherited from QAbstractScrollArea
void addScrollBarWidget (QWidget *widget, Qt::Alignment alignment)
 Adds widget as a scroll bar widget in the location specified by alignment. More...
 
QWidgetcornerWidget () const
 Returns the widget in the corner between the two scroll bars. More...
 
QScrollBarhorizontalScrollBar () const
 Returns the horizontal scroll bar. More...
 
Qt::ScrollBarPolicy horizontalScrollBarPolicy () const
 
QSize maximumViewportSize () const
 Returns the size of the viewport as if the scroll bars had no valid scrolling range. More...
 
QSize minimumSizeHint () const
 Reimplemented Function More...
 
 QAbstractScrollArea (QWidget *parent=0)
 Constructs a viewport. More...
 
QWidgetList scrollBarWidgets (Qt::Alignment alignment)
 Returns a list of the currently set scroll bar widgets. More...
 
void setCornerWidget (QWidget *widget)
 Sets the widget in the corner between the two scroll bars to be widget. More...
 
void setHorizontalScrollBar (QScrollBar *scrollbar)
 Replaces the existing horizontal scroll bar with scrollBar, and sets all the former scroll bar's slider properties on the new scroll bar. More...
 
void setHorizontalScrollBarPolicy (Qt::ScrollBarPolicy)
 
void setVerticalScrollBar (QScrollBar *scrollbar)
 Replaces the existing vertical scroll bar with scrollBar, and sets all the former scroll bar's slider properties on the new scroll bar. More...
 
void setVerticalScrollBarPolicy (Qt::ScrollBarPolicy)
 
void setViewport (QWidget *widget)
 Sets the viewport to be the given widget. More...
 
QSize sizeHint () const
 Reimplemented Function More...
 
QScrollBarverticalScrollBar () const
 Returns the vertical scroll bar. More...
 
Qt::ScrollBarPolicy verticalScrollBarPolicy () const
 
QWidgetviewport () const
 Returns the viewport widget. More...
 
 ~QAbstractScrollArea ()
 Destroys the viewport. More...
 
- Public Functions inherited from QFrame
QRect frameRect () const
 
Shadow frameShadow () const
 
Shape frameShape () const
 
int frameStyle () const
 Returns the frame style. More...
 
int frameWidth () const
 
int lineWidth () const
 
int midLineWidth () const
 
 QFrame (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a frame widget with frame style NoFrame and a 1-pixel frame width. More...
 
void setFrameRect (const QRect &)
 em>Reimplemented Function More...
 
void setFrameShadow (Shadow)
 
void setFrameShape (Shape)
 
void setFrameStyle (int)
 Sets the frame style to style. More...
 
void setLineWidth (int)
 
void setMidLineWidth (int)
 
QSize sizeHint () const
 em>Reimplemented Function More...
 
 ~QFrame ()
 Destroys the frame. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Slots

void resizeSections ()
 Resizes the sections according to their size hints. More...
 
void sectionsAboutToBeRemoved (const QModelIndex &parent, int logicalFirst, int logicalLast)
 This slot is called when sections are removed from the parent. More...
 
void sectionsInserted (const QModelIndex &parent, int logicalFirst, int logicalLast)
 This slot is called when sections are inserted into the parent. More...
 
void updateSection (int logicalIndex)
 Updates the section specified by the given logicalIndex. More...
 
- Protected Slots inherited from QAbstractItemView
virtual void closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
 Closes the given editor, and releases it. More...
 
virtual void commitData (QWidget *editor)
 Commit the data in the editor to the model. More...
 
virtual void editorDestroyed (QObject *editor)
 This function is called when the given editor has been destroyed. More...
 
virtual void horizontalScrollbarAction (int action)
 
virtual void horizontalScrollbarValueChanged (int value)
 
virtual void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)
 This slot is called when rows are about to be removed. More...
 
virtual void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 This slot is called when the selection is changed. More...
 
virtual void updateEditorData ()
 Updates the data shown in the open editor widgets in the view. More...
 
virtual void updateEditorGeometries ()
 Updates the geometry of the open editor widgets in the view. More...
 
virtual void verticalScrollbarAction (int action)
 
virtual void verticalScrollbarValueChanged (int value)
 
- Protected Slots inherited from QAbstractScrollArea
void setupViewport (QWidget *viewport)
 This slot is called by QAbstractScrollArea after setViewport(viewport) has been called. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 

Protected Functions

void currentChanged (const QModelIndex &current, const QModelIndex &old)
 Reimplemented Function More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 Reimplemented Function More...
 
bool event (QEvent *e)
 Reimplemented Function More...
 
int horizontalOffset () const
 Returns the horizontal offset of the header. More...
 
QModelIndex indexAt (const QPoint &p) const
 Empty implementation because the header doesn't show QModelIndex items. More...
 
void initialize ()
 
void initializeSections ()
 
void initializeSections (int start, int end)
 
void initStyleOption (QStyleOptionHeader *option) const
 Initialize option with the values from this QHeaderView. More...
 
bool isIndexHidden (const QModelIndex &index) const
 Empty implementation because the header doesn't show QModelIndex items. More...
 
void mouseDoubleClickEvent (QMouseEvent *e)
 Reimplemented Function More...
 
void mouseMoveEvent (QMouseEvent *e)
 Reimplemented Function More...
 
void mousePressEvent (QMouseEvent *e)
 Reimplemented Function More...
 
void mouseReleaseEvent (QMouseEvent *e)
 Reimplemented Function More...
 
QModelIndex moveCursor (CursorAction, Qt::KeyboardModifiers)
 Empty implementation because the header doesn't show QModelIndex items. More...
 
void paintEvent (QPaintEvent *e)
 Reimplemented Function More...
 
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. More...
 
 QHeaderView (QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent=0)
 
void rowsInserted (const QModelIndex &parent, int start, int end)
 Empty implementation because the header doesn't show QModelIndex items. More...
 
void scrollContentsBy (int dx, int dy)
 Reimplemented Function More...
 
void scrollTo (const QModelIndex &index, ScrollHint hint)
 Empty implementation because the header doesn't show QModelIndex items. More...
 
virtual QSize sectionSizeFromContents (int logicalIndex) const
 Returns the size of the contents of the section specified by the given logicalIndex. More...
 
void setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags flags)
 Selects the items in the given rect according to the specified flags. More...
 
void updateGeometries ()
 Reimplemented Function More...
 
int verticalOffset () const
 Returns the vertical offset of the header. More...
 
bool viewportEvent (QEvent *e)
 Reimplemented Function More...
 
QRect visualRect (const QModelIndex &index) const
 Empty implementation because the header doesn't show QModelIndex items. More...
 
QRegion visualRegionForSelection (const QItemSelection &selection) const
 
- Protected Functions inherited from QAbstractItemView
QPoint dirtyRegionOffset () const
 Returns the offset of the dirty regions in the view. More...
 
void doAutoScroll ()
 
void dragEnterEvent (QDragEnterEvent *event)
 This function is called with the given event when a drag and drop operation enters the widget. More...
 
void dragLeaveEvent (QDragLeaveEvent *event)
 This function is called when the item being dragged leaves the view. More...
 
void dragMoveEvent (QDragMoveEvent *event)
 This function is called continuously with the given event during a drag and drop operation over the widget. More...
 
void dropEvent (QDropEvent *event)
 This function is called with the given event when a drop event occurs over the widget. More...
 
DropIndicatorPosition dropIndicatorPosition () const
 Returns the position of the drop indicator in relation to the closest item. More...
 
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 State is now EditingState; otherwise returns false. More...
 
void executeDelayedItemsLayout ()
 Executes the scheduled layouts without waiting for the event processing to begin. More...
 
void focusInEvent (QFocusEvent *event)
 This function is called with the given event when the widget obtains the focus. More...
 
bool focusNextPrevChild (bool next)
 Reimplemented Function More...
 
void focusOutEvent (QFocusEvent *event)
 This function is called with the given event when the widget looses the focus. More...
 
int horizontalStepsPerItem () const
 Returns the horizontal scroll bar's steps per item. More...
 
void inputMethodEvent (QInputMethodEvent *event)
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *event)
 This function is called with the given event when a key event is sent to the widget. More...
 
 QAbstractItemView (QAbstractItemViewPrivate &, QWidget *parent=0)
 
void resizeEvent (QResizeEvent *event)
 This function is called with the given event when a resize event is sent to the widget. More...
 
void scheduleDelayedItemsLayout ()
 Schedules a layout of the items in the view to be executed when the event processing starts. More...
 
void scrollDirtyRegion (int dx, int dy)
 Prepares the view for scrolling by ({dx},{dy}) pixels by moving the dirty regions in the opposite direction. More...
 
virtual QModelIndexList selectedIndexes () const
 This convenience function returns a list of all selected and non-hidden item indexes in the view. More...
 
virtual QItemSelectionModel::SelectionFlags selectionCommand (const QModelIndex &index, const QEvent *event=0) const
 Returns the SelectionFlags to be used when updating a selection with to include the index specified. More...
 
void setDirtyRegion (const QRegion &region)
 Marks the given region as dirty and schedules it to be updated. More...
 
void setHorizontalStepsPerItem (int steps)
 Sets the horizontal scroll bar's steps per item to steps. More...
 
void setState (State state)
 Sets the item view's state to the given state. More...
 
void setVerticalStepsPerItem (int steps)
 Sets the vertical scroll bar's steps per item to steps. More...
 
void startAutoScroll ()
 
virtual void startDrag (Qt::DropActions supportedActions)
 Starts a drag by calling drag->exec() using the given supportedActions. More...
 
State state () const
 Returns the item view's state. More...
 
void stopAutoScroll ()
 
void timerEvent (QTimerEvent *event)
 This function is called with the given event when a timer event is sent to the widget. More...
 
int verticalStepsPerItem () const
 Returns the vertical scroll bar's steps per item. More...
 
virtual QStyleOptionViewItem viewOptions () const
 Returns a QStyleOptionViewItem structure populated with the view's palette, font, state, alignments etc. More...
 
- Protected Functions inherited from QAbstractScrollArea
void contextMenuEvent (QContextMenuEvent *)
 This event handler can be reimplemented in a subclass to receive context menu events for the viewport() widget. More...
 
void dragEnterEvent (QDragEnterEvent *)
 This event handler can be reimplemented in a subclass to receive drag enter events (passed in event), for the viewport() widget. More...
 
void dragLeaveEvent (QDragLeaveEvent *)
 This event handler can be reimplemented in a subclass to receive drag leave events (passed in event), for the viewport() widget. More...
 
void dragMoveEvent (QDragMoveEvent *)
 This event handler can be reimplemented in a subclass to receive drag move events (passed in event), for the viewport() widget. More...
 
void dropEvent (QDropEvent *)
 This event handler can be reimplemented in a subclass to receive drop events (passed in event), for the viewport() widget. More...
 
bool event (QEvent *)
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *)
 This function is called with key event e when key presses occur. More...
 
void mouseDoubleClickEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse double click events for the viewport() widget. More...
 
void mouseMoveEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse move events for the viewport() widget. More...
 
void mousePressEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse press events for the viewport() widget. More...
 
void mouseReleaseEvent (QMouseEvent *)
 This event handler can be reimplemented in a subclass to receive mouse release events for the viewport() widget. More...
 
void paintEvent (QPaintEvent *)
 This event handler can be reimplemented in a subclass to receive paint events (passed in event), for the viewport() widget. More...
 
 QAbstractScrollArea (QAbstractScrollAreaPrivate &dd, QWidget *parent=0)
 Creates a new QAbstractScrollAreaPrivate, dd with the given parent. More...
 
void resizeEvent (QResizeEvent *)
 This event handler can be reimplemented in a subclass to receive resize events (passed in event), for the viewport() widget. More...
 
void setViewportMargins (int left, int top, int right, int bottom)
 Sets the margins around the scrolling area to left, top, right and bottom. More...
 
void setViewportMargins (const QMargins &margins)
 Sets margins around the scrolling area. More...
 
void wheelEvent (QWheelEvent *)
 This event handler can be reimplemented in a subclass to receive wheel events for the viewport() widget. More...
 
- Protected Functions inherited from QFrame
void changeEvent (QEvent *)
 This event handler can be reimplemented to handle state changes. More...
 
void drawFrame (QPainter *)
 em>Reimplemented Function More...
 
bool event (QEvent *e)
 Reimplemented Function More...
 
void paintEvent (QPaintEvent *)
 This event handler can be reimplemented in a subclass to receive paint events passed in event. More...
 
 QFrame (QFramePrivate &dd, QWidget *parent=0, Qt::WindowFlags f=0)
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void keyReleaseEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget. More...
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void showEvent (QShowEvent *)
 This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

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 More...
 
Qt::Alignment defaultAlignment
 the default alignment of the text in each header section More...
 
int defaultSectionSize
 the default size of the header sections before resizing. More...
 
bool highlightSections
 whether the sections containing selected items are highlighted More...
 
int minimumSectionSize
 the minimum size of the header sections. More...
 
bool showSortIndicator
 whether the sort indicator is shown More...
 
bool stretchLastSection
 whether the last visible section in the header takes up all the available space More...
 

Additional Inherited Members

- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- 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  DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport }
 This enum indicates the position of the drop indicator in relation to the index at the current mouse position: More...
 
enum  State {
  NoState, DraggingState, DragSelectingState, EditingState,
  ExpandingState, CollapsingState, AnimatingState
}
 Describes the different states the view can be in. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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

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 Model/View Classes and is part of Qt's 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.

Moving Header Sections

A header can be fixed in place, or made movable with setMovable(). It can be made clickable with setClickable(), and has resizing behavior in accordance with setResizeMode().

Note
Double-clicking on a header to resize a section only applies for visible rows.

A header will emit sectionMoved() if the user moves a section, sectionResized() if the user resizes a section, and sectionClicked() as well as sectionHandleDoubleClicked() in response to mouse clicks. A header will also emit sectionCountChanged() and sectionAutoResize().

You can identify a section using the logicalIndex() and logicalIndexAt() functions, or by its index position, using the visualIndex() and visualIndexAt() functions. The visual index will change if a section is moved, but the logical index will not change.

Appearance

QTableWidget and QTableView create default headers. If you want the headers to be visible, you can use QFrame::setVisible().

Not all Qt::ItemDataRole will have an effect on a QHeaderView. If you need to draw other roles, you can subclass QHeaderView and reimplement QHeaderView::paintEvent(). QHeaderView respects the following item data roles: Qt::TextAlignmentRole, Qt::DisplayRole, Qt::FontRole, Qt::DecorationRole, Qt::ForegroundRole, and Qt::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 setItemDelegate() function will have no effect.
See also
{Model/View Programming}, QListView, QTableView, QTreeView

Definition at line 58 of file qheaderview.h.

Enumerations

◆ 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 setResizeMode().

  • Fixed The user cannot resize the section. The section can only be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize .
  • Stretch QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically.
  • 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:

  • Custom Use Fixed instead.
See also
setResizeMode() stretchLastSection minimumSectionSize
Enumerator
Interactive 
Stretch 
Fixed 
ResizeToContents 
Custom 

Definition at line 72 of file qheaderview.h.

Constructors and Destructors

◆ QHeaderView() [1/2]

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

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

Definition at line 355 of file qheaderview.cpp.

356  : QAbstractItemView(*new QHeaderViewPrivate, parent)
357 {
358  Q_D(QHeaderView);
359  d->setDefaultValues(orientation);
360  initialize();
361 }
double d
Definition: qnumeric_p.h:62
QAbstractItemView(QWidget *parent=0)
Constructs an abstract item view with the given parent.
void initialize()
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Orientation orientation() const
Returns the orientation of the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ ~QHeaderView()

QHeaderView::~QHeaderView ( )
virtual

Destroys the header.

Definition at line 379 of file qheaderview.cpp.

380 {
381 }

◆ QHeaderView() [2/2]

QHeaderView::QHeaderView ( QHeaderViewPrivate dd,
Qt::Orientation  orientation,
QWidget parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 366 of file qheaderview.cpp.

368  : QAbstractItemView(dd, parent)
369 {
370  Q_D(QHeaderView);
371  d->setDefaultValues(orientation);
372  initialize();
373 }
double d
Definition: qnumeric_p.h:62
QAbstractItemView(QWidget *parent=0)
Constructs an abstract item view with the given parent.
void initialize()
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Orientation orientation() const
Returns the orientation of the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

Functions

◆ cascadingSectionResizes()

bool QHeaderView::cascadingSectionResizes ( ) const

Referenced by setStretchLastSection().

◆ count()

int QHeaderView::count ( ) const

◆ currentChanged()

void QHeaderView::currentChanged ( const QModelIndex current,
const QModelIndex old 
)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2102 of file qheaderview.cpp.

2103 {
2104  Q_D(QHeaderView);
2105 
2106  if (d->orientation == Qt::Horizontal && current.column() != old.column()) {
2107  if (old.isValid() && old.parent() == d->root)
2108  d->viewport->update(QRect(sectionViewportPosition(old.column()), 0,
2109  sectionSize(old.column()), d->viewport->height()));
2110  if (current.isValid() && current.parent() == d->root)
2111  d->viewport->update(QRect(sectionViewportPosition(current.column()), 0,
2112  sectionSize(current.column()), d->viewport->height()));
2113  } else if (d->orientation == Qt::Vertical && current.row() != old.row()) {
2114  if (old.isValid() && old.parent() == d->root)
2115  d->viewport->update(QRect(0, sectionViewportPosition(old.row()),
2116  d->viewport->width(), sectionSize(old.row())));
2117  if (current.isValid() && current.parent() == d->root)
2118  d->viewport->update(QRect(0, sectionViewportPosition(current.row()),
2119  d->viewport->width(), sectionSize(current.row())));
2120  }
2121 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
int row() const
Returns the row this model index refers to.
int sectionViewportPosition(int logicalIndex) const
Returns the section viewport position of the given logicalIndex.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int column() const
Returns the column this model index refers to.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ dataChanged()

void QHeaderView::dataChanged ( const QModelIndex topLeft,
const QModelIndex bottomRight 
)
protectedvirtual

Reimplemented Function

Warning
This function is not part of the public interface.

Reimplemented from QAbstractItemView.

Definition at line 2761 of file qheaderview.cpp.

2762 {
2763  Q_D(QHeaderView);
2764  d->invalidateCachedSizeHint();
2765  if (d->hasAutoResizeSections()) {
2766  bool resizeRequired = d->globalResizeMode == ResizeToContents;
2767  int first = orientation() == Qt::Horizontal ? topLeft.column() : topLeft.row();
2768  int last = orientation() == Qt::Horizontal ? bottomRight.column() : bottomRight.row();
2769  for (int i = first; i <= last && !resizeRequired; ++i)
2770  resizeRequired = (resizeMode(i) == ResizeToContents);
2771  if (resizeRequired)
2772  d->doDelayedResizeSections();
2773  }
2774 }
double d
Definition: qnumeric_p.h:62
ResizeMode resizeMode(int logicalIndex) const
Returns the resize mode that applies to the section specified by the given logicalIndex.
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Orientation orientation() const
Returns the orientation of the header.
int row() const
Returns the row this model index refers to.
int column() const
Returns the column this model index refers to.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ defaultAlignment()

Qt::Alignment QHeaderView::defaultAlignment ( ) const

◆ defaultSectionSize()

int QHeaderView::defaultSectionSize ( ) const

◆ doItemsLayout()

void QHeaderView::doItemsLayout ( )
virtual
Warning
This function is not part of the public interface.

Reimplemented from QAbstractItemView.

Definition at line 1567 of file qheaderview.cpp.

1568 {
1571 }
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
void initializeSections()

◆ event()

bool QHeaderView::event ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2128 of file qheaderview.cpp.

2129 {
2130  Q_D(QHeaderView);
2131  switch (e->type()) {
2132  case QEvent::HoverEnter: {
2133  QHoverEvent *he = static_cast<QHoverEvent*>(e);
2134  d->hover = logicalIndexAt(he->pos());
2135  if (d->hover != -1)
2136  updateSection(d->hover);
2137  break; }
2138  case QEvent::Leave:
2139  case QEvent::HoverLeave: {
2140  if (d->hover != -1)
2141  updateSection(d->hover);
2142  d->hover = -1;
2143  break; }
2144  case QEvent::HoverMove: {
2145  QHoverEvent *he = static_cast<QHoverEvent*>(e);
2146  int oldHover = d->hover;
2147  d->hover = logicalIndexAt(he->pos());
2148  if (d->hover != oldHover) {
2149  if (oldHover != -1)
2150  updateSection(oldHover);
2151  if (d->hover != -1)
2152  updateSection(d->hover);
2153  }
2154  break; }
2155  case QEvent::Timer: {
2156  QTimerEvent *te = static_cast<QTimerEvent*>(e);
2157  if (te->timerId() == d->delayedResize.timerId()) {
2158  d->delayedResize.stop();
2159  resizeSections();
2160  }
2161  break; }
2162  default:
2163  break;
2164  }
2165  return QAbstractItemView::event(e);
2166 }
double d
Definition: qnumeric_p.h:62
void resizeSections()
Resizes the sections according to their size hints.
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
#define Q_D(Class)
Definition: qglobal.h:2482
void updateSection(int logicalIndex)
Updates the section specified by the given logicalIndex.
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:131
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
bool event(QEvent *event)
Reimplemented Function
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ geometriesChanged

void QHeaderView::geometriesChanged ( )
signal

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

Since
4.2

Referenced by viewportEvent().

◆ 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 1675 of file qheaderview.cpp.

Referenced by setModel().

1676 {
1677  Q_D(QHeaderView);
1678  if (d->orientation != orientation)
1679  return;
1680 
1681  if (logicalFirst < 0 || logicalLast < 0 || logicalFirst >= count() || logicalLast >= count())
1682  return;
1683 
1684  d->invalidateCachedSizeHint();
1685 
1686  int firstVisualIndex = INT_MAX, lastVisualIndex = -1;
1687 
1688  for (int section = logicalFirst; section <= logicalLast; ++section) {
1689  const int visual = visualIndex(section);
1690  firstVisualIndex = qMin(firstVisualIndex, visual);
1691  lastVisualIndex = qMax(lastVisualIndex, visual);
1692  }
1693 
1694  d->executePostedResize();
1695  const int first = d->headerSectionPosition(firstVisualIndex),
1696  last = d->headerSectionPosition(lastVisualIndex)
1697  + d->headerSectionSize(lastVisualIndex);
1698 
1699  if (orientation == Qt::Horizontal) {
1700  d->viewport->update(first, 0, last - first, d->viewport->height());
1701  } else {
1702  d->viewport->update(0, first, d->viewport->width(), last - first);
1703  }
1704 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Qt::Orientation orientation() const
Returns the orientation of the header.
int count() const
Returns the number of sections in the header.
#define INT_MAX
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ hiddenSectionCount()

int QHeaderView::hiddenSectionCount ( ) const

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

Since
4.1
See also
setSectionHidden(), isSectionHidden()

Definition at line 1045 of file qheaderview.cpp.

1046 {
1047  Q_D(const QHeaderView);
1048  return d->hiddenSectionSize.count();
1049 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ hideSection()

void QHeaderView::hideSection ( int  logicalIndex)
inline

Hides the section specified by logicalIndex.

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

Definition at line 239 of file qheaderview.h.

240 { setSectionHidden(alogicalIndex, true); }
void setSectionHidden(int logicalIndex, bool hide)
If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown...

◆ highlightSections()

bool QHeaderView::highlightSections ( ) const

Referenced by setHighlightSections().

◆ horizontalOffset()

int QHeaderView::horizontalOffset ( ) const
protectedvirtual

Returns the horizontal offset of the header.

This is 0 for vertical headers.

See also
offset()

Implements QAbstractItemView.

Definition at line 2710 of file qheaderview.cpp.

2711 {
2712  Q_D(const QHeaderView);
2713  if (d->orientation == Qt::Horizontal)
2714  return d->offset;
2715  return 0;
2716 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ indexAt()

QModelIndex QHeaderView::indexAt ( const QPoint p) const
protectedvirtual

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

Reimplemented Function

Warning
This function is not part of the public interface.

Implements QAbstractItemView.

Definition at line 2830 of file qheaderview.cpp.

2831 {
2832  return QModelIndex();
2833 }
The QModelIndex class is used to locate data in a data model.

◆ initialize()

void QHeaderView::initialize ( )
protected
Warning
This function is not part of the public interface.

Definition at line 386 of file qheaderview.cpp.

Referenced by QHeaderView().

387 {
388  Q_D(QHeaderView);
393  d->viewport->setMouseTracking(true);
394  d->viewport->setBackgroundRole(QPalette::Button);
395  d->textElideMode = Qt::ElideNone;
396  delete d->itemDelegate;
397 }
double d
Definition: qnumeric_p.h:62
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
#define Q_D(Class)
Definition: qglobal.h:2482
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
void setFrameStyle(int)
Sets the frame style to style.
Definition: qframe.cpp:329
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ initializeSections() [1/2]

void QHeaderView::initializeSections ( )
protected
Warning
This function is not part of the public interface.

Definition at line 2004 of file qheaderview.cpp.

Referenced by doItemsLayout(), reset(), setModel(), and setResizeMode().

2005 {
2006  Q_D(QHeaderView);
2007  const int oldCount = d->sectionCount;
2008  const int newCount = d->modelSectionCount();
2009  if (newCount <= 0) {
2010  d->clear();
2011  emit sectionCountChanged(oldCount, 0);
2012  } else if (newCount != oldCount) {
2013  const int min = qBound(0, oldCount, newCount - 1);
2014  initializeSections(min, newCount - 1);
2015  if (stretchLastSection()) // we've already gotten the size hint
2016  d->lastSectionSize = sectionSize(logicalIndex(d->sectionCount - 1));
2017 
2018  //make sure we update the hidden sections
2019  if (newCount < oldCount)
2020  d->updateHiddenSections(0, newCount-1);
2021  }
2022 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void sectionCountChanged(int oldCount, int newCount)
This signal is emitted when the number of sections changes, i.
#define emit
Definition: qobjectdefs.h:76
void initializeSections()
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
bool stretchLastSection() const
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ initializeSections() [2/2]

void QHeaderView::initializeSections ( int  start,
int  end 
)
protected
Warning
This function is not part of the public interface.

Definition at line 2028 of file qheaderview.cpp.

2029 {
2030  Q_D(QHeaderView);
2031 
2032  Q_ASSERT(start >= 0);
2033  Q_ASSERT(end >= 0);
2034 
2035  d->invalidateCachedSizeHint();
2036 
2037  if (end + 1 < d->sectionCount) {
2038  int newCount = end + 1;
2039  d->removeSectionsFromSpans(newCount, d->sectionCount);
2040  if (!d->hiddenSectionSize.isEmpty()) {
2041  if (d->sectionCount - newCount > d->hiddenSectionSize.count()) {
2042  for (int i = end + 1; i < d->sectionCount; ++i)
2043  d->hiddenSectionSize.remove(i);
2044  } else {
2045  QHash<int, int>::iterator it = d->hiddenSectionSize.begin();
2046  while (it != d->hiddenSectionSize.end()) {
2047  if (it.key() > end)
2048  it = d->hiddenSectionSize.erase(it);
2049  else
2050  ++it;
2051  }
2052  }
2053  }
2054  }
2055 
2056  int oldCount = d->sectionCount;
2057  d->sectionCount = end + 1;
2058 
2059  if (!d->logicalIndices.isEmpty()) {
2060  if (oldCount <= d->sectionCount) {
2061  d->logicalIndices.resize(d->sectionCount);
2062  d->visualIndices.resize(d->sectionCount);
2063  for (int i = oldCount; i < d->sectionCount; ++i) {
2064  d->logicalIndices[i] = i;
2065  d->visualIndices[i] = i;
2066  }
2067  } else {
2068  int j = 0;
2069  for (int i = 0; i < oldCount; ++i) {
2070  int v = d->logicalIndices.at(i);
2071  if (v < d->sectionCount) {
2072  d->logicalIndices[j] = v;
2073  d->visualIndices[v] = j;
2074  j++;
2075  }
2076  }
2077  d->logicalIndices.resize(d->sectionCount);
2078  d->visualIndices.resize(d->sectionCount);
2079  }
2080  }
2081 
2082  if (d->globalResizeMode == Stretch)
2083  d->stretchSections = d->sectionCount;
2084  else if (d->globalResizeMode == ResizeToContents)
2085  d->contentsSections = d->sectionCount;
2086  if (!d->sectionHidden.isEmpty())
2087  d->sectionHidden.resize(d->sectionCount);
2088 
2089  if (d->sectionCount > oldCount)
2090  d->createSectionSpan(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode);
2091  //Q_ASSERT(d->headerLength() == d->length);
2092 
2093  if (d->sectionCount != oldCount)
2094  emit sectionCountChanged(oldCount, d->sectionCount);
2095  d->viewport->update();
2096 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void sectionCountChanged(int oldCount, int newCount)
This signal is emitted when the number of sections changes, i.
#define emit
Definition: qobjectdefs.h:76
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
static const KeyPair *const end
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ initStyleOption()

void QHeaderView::initStyleOption ( QStyleOptionHeader option) const
protected

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

Definition at line 3046 of file qheaderview.cpp.

Referenced by paintSection(), and sectionSizeFromContents().

3047 {
3048  Q_D(const QHeaderView);
3049  option->initFrom(this);
3051  option->orientation = d->orientation;
3052  if (d->orientation == Qt::Horizontal)
3053  option->state |= QStyle::State_Horizontal;
3054  if (isEnabled())
3055  option->state |= QStyle::State_Enabled;
3056  option->section = 0;
3057 }
double d
Definition: qnumeric_p.h:62
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Orientation orientation
the header&#39;s orientation (horizontal or vertical)
Definition: qstyleoption.h:270
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
bool isEnabled() const
Definition: qwidget.h:948
int section
which section of the header is being painted
Definition: qstyleoption.h:262
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ isClickable()

bool QHeaderView::isClickable ( ) const

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.

See also
setClickable()

Definition at line 1201 of file qheaderview.cpp.

1202 {
1203  Q_D(const QHeaderView);
1204  return d->clickableSections;
1205 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ isIndexHidden()

bool QHeaderView::isIndexHidden ( const QModelIndex index) const
protectedvirtual

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

Reimplemented Function

Warning
This function is not part of the public interface.

Implements QAbstractItemView.

Definition at line 2845 of file qheaderview.cpp.

2846 {
2847  return true; // the header view has no items, just sections
2848 }

◆ isMovable()

bool QHeaderView::isMovable ( ) const

Returns true if the header can be moved by the user; otherwise returns false.

See also
setMovable()

Definition at line 1172 of file qheaderview.cpp.

1173 {
1174  Q_D(const QHeaderView);
1175  return d->movableSections;
1176 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 1024 of file qheaderview.cpp.

Referenced by QTreeViewPrivate::adjustViewOptionsForIndex(), QTreeViewPrivate::calcLogicalIndices(), QTreeViewPrivate::columnRanges(), QTableViewPrivate::isColumnHidden(), QTableViewPrivate::isRowHidden(), QAccessibleItemRow::logicalFromChild(), QTableView::paintEvent(), resizeSection(), QFileDialog::restoreState(), sectionsInserted(), sectionSize(), sectionSizeHint(), and sizeHint().

1025 {
1026  Q_D(const QHeaderView);
1027  d->executePostedLayout();
1028  if (logicalIndex >= d->sectionHidden.count() || logicalIndex < 0 || logicalIndex >= d->sectionCount)
1029  return false;
1030  int visual = visualIndex(logicalIndex);
1031  Q_ASSERT(visual != -1);
1032  return d->sectionHidden.testBit(visual);
1033 }
double d
Definition: qnumeric_p.h:62
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ isSortIndicatorShown()

bool QHeaderView::isSortIndicatorShown ( ) const

Definition at line 1341 of file qheaderview.cpp.

Referenced by paintSection(), and sectionSizeFromContents().

1342 {
1343  Q_D(const QHeaderView);
1344  return d->sortIndicatorShown;
1345 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ length()

int QHeaderView::length ( ) const

Returns the length along the orientation of the header.

See also
sizeHint(), setResizeMode(), offset()

Definition at line 560 of file qheaderview.cpp.

Referenced by QHeaderViewPrivate::clear(), QHeaderViewPrivate::createSectionSpan(), QTreeView::drawRow(), QTableView::paintEvent(), QHeaderViewPrivate::read(), QHeaderViewPrivate::removeSectionsFromSpans(), QHeaderViewPrivate::setDefaultSectionSize(), setOffsetToLastSection(), QTreeViewPrivate::updateScrollBars(), and QHeaderViewPrivate::write().

561 {
562  Q_D(const QHeaderView);
563  d->executePostedLayout();
564  d->executePostedResize();
565  //Q_ASSERT(d->headerLength() == d->length);
566  return d->length;
567 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 1142 of file qheaderview.cpp.

Referenced by QHeaderViewPrivate::_q_layoutAboutToBeChanged(), QHeaderViewPrivate::_q_sectionsRemoved(), QTreeViewPrivate::adjustViewOptionsForIndex(), QTreeViewPrivate::calcLogicalIndices(), QTreeViewPrivate::columnRanges(), QTreeView::drawRow(), initializeSections(), logicalIndexAt(), moveSection(), QTableView::paintEvent(), paintEvent(), paintSection(), QHeaderViewPrivate::resizeSections(), QHeaderViewPrivate::resizeSectionSpan(), QHeaderViewPrivate::sectionHandleAt(), sectionSizeFromContents(), QTableViewPrivate::sectionSpanEndLogical(), QHeaderViewPrivate::setDefaultSectionSize(), setSortIndicator(), QTableViewPrivate::spanContainsSection(), QHeaderViewPrivate::updateHiddenSections(), QTreeViewPrivate::updateScrollBars(), visualIndex(), QTreeWidget::visualItemRect(), and visualRegionForSelection().

1143 {
1144  Q_D(const QHeaderView);
1145  if (visualIndex < 0 || visualIndex >= d->sectionCount)
1146  return -1;
1147  return d->logicalIndex(visualIndex);
1148 }
double d
Definition: qnumeric_p.h:62
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ logicalIndexAt() [1/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 669 of file qheaderview.cpp.

Referenced by QTreeViewPrivate::columnAt(), event(), QTreeViewPrivate::itemDecorationAt(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), QTableViewPrivate::selectColumn(), QTableViewPrivate::selectRow(), viewportEvent(), and QTreeWidget::visualItemRect().

670 {
671  const int visual = visualIndexAt(position);
672  if (visual > -1)
673  return logicalIndex(visual);
674  return -1;
675 }
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
int visualIndexAt(int position) const
Returns the visual index of the section that covers the given position in the viewport.
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...

◆ logicalIndexAt() [2/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 235 of file qheaderview.h.

236 { return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
Qt::Orientation orientation() const
Returns the orientation of the header.
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.

◆ logicalIndexAt() [3/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 237 of file qheaderview.h.

238 { return logicalIndexAt(apos.x(), apos.y()); }
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.

◆ minimumSectionSize()

int QHeaderView::minimumSectionSize ( ) const

◆ mouseDoubleClickEvent()

void QHeaderView::mouseDoubleClickEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2453 of file qheaderview.cpp.

2454 {
2455  Q_D(QHeaderView);
2456  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2457  int handle = d->sectionHandleAt(pos);
2458  if (handle > -1 && resizeMode(handle) == Interactive) {
2460 #ifndef QT_NO_CURSOR
2461  Qt::CursorShape splitCursor = (d->orientation == Qt::Horizontal)
2463  if (cursor().shape() == splitCursor) {
2464  // signal handlers may have changed the section size
2465  handle = d->sectionHandleAt(pos);
2466  if (!(handle > -1 && resizeMode(handle) == Interactive))
2468  }
2469 #endif
2470  } else {
2472  }
2473 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
QCursor cursor() const
ResizeMode resizeMode(int logicalIndex) const
Returns the resize mode that applies to the section specified by the given logicalIndex.
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
#define emit
Definition: qobjectdefs.h:76
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
void sectionHandleDoubleClicked(int logicalIndex)
This signal is emitted when a section is double-clicked.
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:98
void sectionDoubleClicked(int logicalIndex)
This signal is emitted when a section is double-clicked.
CursorShape
Definition: qnamespace.h:1262
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
int x() const
Returns the x position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:97
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition: qcursor.cpp:469

◆ mouseMoveEvent()

void QHeaderView::mouseMoveEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2314 of file qheaderview.cpp.

2315 {
2316  Q_D(QHeaderView);
2317  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2318  if (pos < 0)
2319  return;
2320  if (e->buttons() == Qt::NoButton) {
2321 #if !defined(Q_WS_MAC)
2322  // Under Cocoa, when the mouse button is released, may include an extra
2323  // simulated mouse moved event. The state of the buttons when this event
2324  // is generated is already "no button" and the code below gets executed
2325  // just before the mouseReleaseEvent and resets the state. This prevents
2326  // column dragging from working. So this code is disabled under Cocoa.
2327  d->state = QHeaderViewPrivate::NoState;
2328  d->pressed = -1;
2329 #endif
2330  }
2331  switch (d->state) {
2333  Q_ASSERT(d->originalSize != -1);
2334  if (d->cascadingResizing) {
2335  int delta = d->reverse() ? d->lastPos - pos : pos - d->lastPos;
2336  int visual = visualIndex(d->section);
2337  d->cascadingResize(visual, d->headerSectionSize(visual) + delta);
2338  } else {
2339  int delta = d->reverse() ? d->firstPos - pos : pos - d->firstPos;
2340  resizeSection(d->section, qMax(d->originalSize + delta, minimumSectionSize()));
2341  }
2342  d->lastPos = pos;
2343  return;
2344  }
2346  if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()
2347  || !d->sectionIndicator->isHidden()) {
2348  int visual = visualIndexAt(pos);
2349  if (visual == -1)
2350  return;
2351  int posThreshold = d->headerSectionPosition(visual) - d->offset + d->headerSectionSize(visual) / 2;
2352  int moving = visualIndex(d->section);
2353  if (visual < moving) {
2354  if (pos < posThreshold)
2355  d->target = d->logicalIndex(visual);
2356  else
2357  d->target = d->logicalIndex(visual + 1);
2358  } else if (visual > moving) {
2359  if (pos > posThreshold)
2360  d->target = d->logicalIndex(visual);
2361  else
2362  d->target = d->logicalIndex(visual - 1);
2363  } else {
2364  d->target = d->section;
2365  }
2366  d->updateSectionIndicator(d->section, pos);
2367  }
2368  return;
2369  }
2371  int logical = logicalIndexAt(pos);
2372  if (logical == d->pressed)
2373  return; // nothing to do
2374  else if (d->pressed != -1)
2375  updateSection(d->pressed);
2376  d->pressed = logical;
2377  if (d->clickableSections && logical != -1) {
2378  emit sectionEntered(d->pressed);
2379  updateSection(d->pressed);
2380  }
2381  return;
2382  }
2384 #ifndef QT_NO_CURSOR
2385  int handle = d->sectionHandleAt(pos);
2386  bool hasCursor = testAttribute(Qt::WA_SetCursor);
2387  if (handle != -1 && (resizeMode(handle) == Interactive)) {
2388  if (!hasCursor)
2390  } else if (hasCursor) {
2391  unsetCursor();
2392  }
2393 #endif
2394  return;
2395  }
2396  default:
2397  break;
2398  }
2399 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
void unsetCursor()
Definition: qwidget.cpp:5311
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
ResizeMode resizeMode(int logicalIndex) const
Returns the resize mode that applies to the section specified by the given logicalIndex.
int minimumSectionSize() const
void resizeSection(int logicalIndex, int size)
Resizes the section specified by logicalIndex to size measured in pixels.
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void updateSection(int logicalIndex)
Updates the section specified by the given logicalIndex.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
#define emit
Definition: qobjectdefs.h:76
void sectionEntered(int logicalIndex)
This signal is emitted when the cursor moves over the section and the left mouse button is pressed...
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
static int startDragDistance()
int visualIndexAt(int position) const
Returns the visual index of the section that covers the given position in the viewport.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:98
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
int x() const
Returns the x position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:97

◆ mousePressEvent()

void QHeaderView::mousePressEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2276 of file qheaderview.cpp.

2277 {
2278  Q_D(QHeaderView);
2279  if (d->state != QHeaderViewPrivate::NoState || e->button() != Qt::LeftButton)
2280  return;
2281  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2282  int handle = d->sectionHandleAt(pos);
2283  d->originalSize = -1; // clear the stored original size
2284  if (handle == -1) {
2285  d->pressed = logicalIndexAt(pos);
2286  if (d->clickableSections)
2287  emit sectionPressed(d->pressed);
2288  if (d->movableSections) {
2289  d->section = d->target = d->pressed;
2290  if (d->section == -1)
2291  return;
2293  d->setupSectionIndicator(d->section, pos);
2294  } else if (d->clickableSections && d->pressed != -1) {
2295  updateSection(d->pressed);
2297  }
2298  } else if (resizeMode(handle) == Interactive) {
2299  d->originalSize = sectionSize(handle);
2301  d->section = handle;
2302  }
2303 
2304  d->firstPos = pos;
2305  d->lastPos = pos;
2306 
2307  d->clearCascadingSections();
2308 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
ResizeMode resizeMode(int logicalIndex) const
Returns the resize mode that applies to the section specified by the given logicalIndex.
#define Q_D(Class)
Definition: qglobal.h:2482
void updateSection(int logicalIndex)
Updates the section specified by the given logicalIndex.
#define emit
Definition: qobjectdefs.h:76
void sectionPressed(int logicalIndex)
This signal is emitted when a section is pressed.
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:98
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
int x() const
Returns the x position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:97

◆ mouseReleaseEvent()

void QHeaderView::mouseReleaseEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2405 of file qheaderview.cpp.

2406 {
2407  Q_D(QHeaderView);
2408  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2409  switch (d->state) {
2411  if (!d->sectionIndicator->isHidden()) { // moving
2412  int from = visualIndex(d->section);
2413  Q_ASSERT(from != -1);
2414  int to = visualIndex(d->target);
2415  Q_ASSERT(to != -1);
2416  moveSection(from, to);
2417  d->section = d->target = -1;
2418  d->updateSectionIndicator(d->section, pos);
2419  break;
2420  } // not moving
2422  if (!d->clickableSections) {
2423  int section = logicalIndexAt(pos);
2424  updateSection(section);
2425  }
2426  // fall through
2428  if (d->clickableSections) {
2429  int section = logicalIndexAt(pos);
2430  if (section != -1 && section == d->pressed) {
2431  d->flipSortIndicator(section);
2432  emit sectionClicked(section);
2433  }
2434  if (d->pressed != -1)
2435  updateSection(d->pressed);
2436  }
2437  break;
2439  d->originalSize = -1;
2440  d->clearCascadingSections();
2441  break;
2442  default:
2443  break;
2444  }
2445  d->state = QHeaderViewPrivate::NoState;
2446  d->pressed = -1;
2447 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
void sectionClicked(int logicalIndex)
This signal is emitted when a section is clicked.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void moveSection(int from, int to)
Moves the section at visual index from to occupy visual index to.
void updateSection(int logicalIndex)
Updates the section specified by the given logicalIndex.
#define emit
Definition: qobjectdefs.h:76
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:98
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
int x() const
Returns the x position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:97

◆ moveCursor()

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

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

Reimplemented Function

Warning
This function is not part of the public interface.

Implements QAbstractItemView.

Definition at line 2860 of file qheaderview.cpp.

2861 {
2862  return QModelIndex();
2863 }
The QModelIndex class is used to locate data in a data model.

◆ 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 773 of file qheaderview.cpp.

Referenced by mouseReleaseEvent().

774 {
775  Q_D(QHeaderView);
776 
777  d->executePostedLayout();
778  if (from < 0 || from >= d->sectionCount || to < 0 || to >= d->sectionCount)
779  return;
780 
781  if (from == to) {
782  int logical = logicalIndex(from);
783  Q_ASSERT(logical != -1);
784  updateSection(logical);
785  return;
786  }
787 
788  if (stretchLastSection() && to == d->lastVisibleVisualIndex())
789  d->lastSectionSize = sectionSize(from);
790 
791  //int oldHeaderLength = length(); // ### for debugging; remove later
792  d->initializeIndexMapping();
793 
794  QBitArray sectionHidden = d->sectionHidden;
795  int *visualIndices = d->visualIndices.data();
796  int *logicalIndices = d->logicalIndices.data();
797  int logical = logicalIndices[from];
798  int visual = from;
799 
800  int affected_count = qAbs(to - from) + 1;
801  QVarLengthArray<int> sizes(affected_count);
802  QVarLengthArray<ResizeMode> modes(affected_count);
803 
804  // move sections and indices
805  if (to > from) {
806  sizes[to - from] = d->headerSectionSize(from);
807  modes[to - from] = d->headerSectionResizeMode(from);
808  while (visual < to) {
809  sizes[visual - from] = d->headerSectionSize(visual + 1);
810  modes[visual - from] = d->headerSectionResizeMode(visual + 1);
811  if (!sectionHidden.isEmpty())
812  sectionHidden.setBit(visual, sectionHidden.testBit(visual + 1));
813  visualIndices[logicalIndices[visual + 1]] = visual;
814  logicalIndices[visual] = logicalIndices[visual + 1];
815  ++visual;
816  }
817  } else {
818  sizes[0] = d->headerSectionSize(from);
819  modes[0] = d->headerSectionResizeMode(from);
820  while (visual > to) {
821  sizes[visual - to] = d->headerSectionSize(visual - 1);
822  modes[visual - to] = d->headerSectionResizeMode(visual - 1);
823  if (!sectionHidden.isEmpty())
824  sectionHidden.setBit(visual, sectionHidden.testBit(visual - 1));
825  visualIndices[logicalIndices[visual - 1]] = visual;
826  logicalIndices[visual] = logicalIndices[visual - 1];
827  --visual;
828  }
829  }
830  if (!sectionHidden.isEmpty()) {
831  sectionHidden.setBit(to, d->sectionHidden.testBit(from));
832  d->sectionHidden = sectionHidden;
833  }
834  visualIndices[logical] = to;
835  logicalIndices[to] = logical;
836 
837  //Q_ASSERT(oldHeaderLength == length());
838  // move sizes
839  // ### check for spans of section sizes here
840  if (to > from) {
841  for (visual = from; visual <= to; ++visual) {
842  int size = sizes[visual - from];
843  ResizeMode mode = modes[visual - from];
844  d->createSectionSpan(visual, visual, size, mode);
845  }
846  } else {
847  for (visual = to; visual <= from; ++visual) {
848  int size = sizes[visual - to];
849  ResizeMode mode = modes[visual - to];
850  d->createSectionSpan(visual, visual, size, mode);
851  }
852  }
853  //Q_ASSERT(d->headerLength() == length());
854  //Q_ASSERT(oldHeaderLength == length());
855  //Q_ASSERT(d->logicalIndices.count() == d->sectionCount);
856 
857  if (d->hasAutoResizeSections())
858  d->doDelayedResizeSections();
859  d->viewport->update();
860 
861  emit sectionMoved(logical, from, to);
862 }
void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex)
This signal is emitted when a section is moved.
double d
Definition: qnumeric_p.h:62
void setBit(int i)
Sets the bit at index position i to 1.
Definition: qbitarray.h:128
QSize size() const
ResizeMode
The resize mode specifies the behavior of the header sections.
Definition: qheaderview.h:72
bool testBit(int i) const
Returns true if the bit at index position i is 1; otherwise returns false.
Definition: qbitarray.h:124
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void updateSection(int logicalIndex)
Updates the section specified by the given logicalIndex.
#define emit
Definition: qobjectdefs.h:76
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
bool stretchLastSection() const
bool isEmpty() const
Returns true if this bit array has size 0; otherwise returns false.
Definition: qbitarray.h:78
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 480 of file qheaderview.cpp.

Referenced by QTreeView::drawRow(), QTableView::paintEvent(), and paintEvent().

481 {
482  Q_D(const QHeaderView);
483  return d->offset;
484 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ orientation()

Qt::Orientation QHeaderView::orientation ( ) const

◆ paintEvent()

void QHeaderView::paintEvent ( QPaintEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2172 of file qheaderview.cpp.

2173 {
2174  Q_D(QHeaderView);
2175 
2176  if (count() == 0)
2177  return;
2178 
2179  QPainter painter(d->viewport);
2180  const QPoint offset = d->scrollDelayOffset;
2181  QRect translatedEventRect = e->rect();
2182  translatedEventRect.translate(offset);
2183 
2184  int start = -1;
2185  int end = -1;
2186  if (d->orientation == Qt::Horizontal) {
2187  start = visualIndexAt(translatedEventRect.left());
2188  end = visualIndexAt(translatedEventRect.right());
2189  } else {
2190  start = visualIndexAt(translatedEventRect.top());
2191  end = visualIndexAt(translatedEventRect.bottom());
2192  }
2193 
2194  if (d->reverse()) {
2195  start = (start == -1 ? count() - 1 : start);
2196  end = (end == -1 ? 0 : end);
2197  } else {
2198  start = (start == -1 ? 0 : start);
2199  end = (end == -1 ? count() - 1 : end);
2200  }
2201 
2202  int tmp = start;
2203  start = qMin(start, end);
2204  end = qMax(tmp, end);
2205 
2206  d->prepareSectionSelected(); // clear and resize the bit array
2207 
2208  QRect currentSectionRect;
2209  int logical;
2210  const int width = d->viewport->width();
2211  const int height = d->viewport->height();
2212  for (int i = start; i <= end; ++i) {
2213  if (d->isVisualIndexHidden(i))
2214  continue;
2215  painter.save();
2216  logical = logicalIndex(i);
2217  if (d->orientation == Qt::Horizontal) {
2218  currentSectionRect.setRect(sectionViewportPosition(logical), 0, sectionSize(logical), height);
2219  } else {
2220  currentSectionRect.setRect(0, sectionViewportPosition(logical), width, sectionSize(logical));
2221  }
2222  currentSectionRect.translate(offset);
2223 
2224  QVariant variant = d->model->headerData(logical, d->orientation,
2225  Qt::FontRole);
2226  if (variant.isValid() && variant.canConvert<QFont>()) {
2227  QFont sectionFont = qvariant_cast<QFont>(variant);
2228  painter.setFont(sectionFont);
2229  }
2230  paintSection(&painter, currentSectionRect, logical);
2231  painter.restore();
2232  }
2233 
2234  QStyleOption opt;
2235  opt.init(this);
2236  // Paint the area beyond where there are indexes
2237  if (d->reverse()) {
2239  if (currentSectionRect.left() > translatedEventRect.left()) {
2240  opt.rect = QRect(translatedEventRect.left(), 0,
2241  currentSectionRect.left() - translatedEventRect.left(), height);
2242  style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, &painter, this);
2243  }
2244  } else if (currentSectionRect.right() < translatedEventRect.right()) {
2245  // paint to the right
2247  opt.rect = QRect(currentSectionRect.right() + 1, 0,
2248  translatedEventRect.right() - currentSectionRect.right(), height);
2249  style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, &painter, this);
2250  } else if (currentSectionRect.bottom() < translatedEventRect.bottom()) {
2251  // paint the bottom section
2252  opt.state &= ~QStyle::State_Horizontal;
2253  opt.rect = QRect(0, currentSectionRect.bottom() + 1,
2254  width, height - currentSectionRect.bottom() - 1);
2255  style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, &painter, this);
2256  }
2257 
2258 #if 0
2259  // ### visualize section spans
2260  for (int a = 0, i = 0; i < d->sectionSpans.count(); ++i) {
2261  QColor color((i & 4 ? 255 : 0), (i & 2 ? 255 : 0), (i & 1 ? 255 : 0));
2262  if (d->orientation == Qt::Horizontal)
2263  painter.fillRect(a - d->offset, 0, d->sectionSpans.at(i).size, 4, color);
2264  else
2265  painter.fillRect(0, a - d->offset, 4, d->sectionSpans.at(i).size, color);
2266  a += d->sectionSpans.at(i).size;
2267  }
2268 
2269 #endif
2270 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void init(const QWidget *w)
Use initFrom(widget) instead.
long ASN1_INTEGER_get ASN1_INTEGER * a
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
int offset() const
Returns the offset of the header: this is the header&#39;s left-most (or top-most for vertical headers) v...
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
int width() const
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...
int sectionViewportPosition(int logicalIndex) const
Returns the section viewport position of the given logicalIndex.
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int visualIndexAt(int position) const
Returns the visual index of the section that covers the given position in the viewport.
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
int count() const
Returns the number of sections in the header.
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
const char * variant
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition: qevent.h:305
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
static const KeyPair *const end
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 2560 of file qheaderview.cpp.

Referenced by paintEvent().

2561 {
2562  Q_D(const QHeaderView);
2563  if (!rect.isValid())
2564  return;
2565  // get the state of the section
2566  QStyleOptionHeader opt;
2567  initStyleOption(&opt);
2569  if (isEnabled())
2570  state |= QStyle::State_Enabled;
2571  if (window()->isActiveWindow())
2572  state |= QStyle::State_Active;
2573  if (d->clickableSections) {
2574  if (logicalIndex == d->hover)
2575  state |= QStyle::State_MouseOver;
2576  if (logicalIndex == d->pressed)
2577  state |= QStyle::State_Sunken;
2578  else if (d->highlightSelected) {
2579  if (d->sectionIntersectsSelection(logicalIndex))
2580  state |= QStyle::State_On;
2581  if (d->isSectionSelected(logicalIndex))
2582  state |= QStyle::State_Sunken;
2583  }
2584 
2585  }
2589 
2590  // setup the style options structure
2591  QVariant textAlignment = d->model->headerData(logicalIndex, d->orientation,
2593  opt.rect = rect;
2594  opt.section = logicalIndex;
2595  opt.state |= state;
2596  opt.textAlignment = Qt::Alignment(textAlignment.isValid()
2597  ? Qt::Alignment(textAlignment.toInt())
2598  : d->defaultAlignment);
2599 
2601  opt.text = d->model->headerData(logicalIndex, d->orientation,
2602  Qt::DisplayRole).toString();
2603  if (d->textElideMode != Qt::ElideNone)
2604  opt.text = opt.fontMetrics.elidedText(opt.text, d->textElideMode , rect.width() - 4);
2605 
2606  QVariant variant = d->model->headerData(logicalIndex, d->orientation,
2608  opt.icon = qvariant_cast<QIcon>(variant);
2609  if (opt.icon.isNull())
2610  opt.icon = qvariant_cast<QPixmap>(variant);
2611  QVariant foregroundBrush = d->model->headerData(logicalIndex, d->orientation,
2613  if (foregroundBrush.canConvert<QBrush>())
2614  opt.palette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(foregroundBrush));
2615 
2616  QPointF oldBO = painter->brushOrigin();
2617  QVariant backgroundBrush = d->model->headerData(logicalIndex, d->orientation,
2619  if (backgroundBrush.canConvert<QBrush>()) {
2620  opt.palette.setBrush(QPalette::Button, qvariant_cast<QBrush>(backgroundBrush));
2621  opt.palette.setBrush(QPalette::Window, qvariant_cast<QBrush>(backgroundBrush));
2622  painter->setBrushOrigin(opt.rect.topLeft());
2623  }
2624 
2625  // the section position
2626  int visual = visualIndex(logicalIndex);
2627  Q_ASSERT(visual != -1);
2628  if (count() == 1)
2630  else if (visual == 0)
2632  else if (visual == count() - 1)
2634  else
2636  opt.orientation = d->orientation;
2637  // the selected position
2638  bool previousSelected = d->isSectionSelected(this->logicalIndex(visual - 1));
2639  bool nextSelected = d->isSectionSelected(this->logicalIndex(visual + 1));
2640  if (previousSelected && nextSelected)
2642  else if (previousSelected)
2644  else if (nextSelected)
2646  else
2648  // draw the section
2649  style()->drawControl(QStyle::CE_Header, &opt, painter, this);
2650 
2651  painter->setBrushOrigin(oldBO);
2652 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:251
int sortIndicatorSection() const
Returns the logical index of the section that has a sort indicator.
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
void initStyleOption(QStyleOptionHeader *option) const
Initialize option with the values from this QHeaderView.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
SortIndicator sortIndicator
the direction the sort indicator should be drawn
Definition: qstyleoption.h:269
QString text
the text of the header
Definition: qstyleoption.h:263
bool isActiveWindow() const
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
Qt::Orientation orientation
the header&#39;s orientation (horizontal or vertical)
Definition: qstyleoption.h:270
Qt::Alignment textAlignment
the alignment flags for the text of the header
Definition: qstyleoption.h:264
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
QStyle * style() const
Definition: qwidget.cpp:2742
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
QPoint brushOrigin() const
Returns the currently set brush origin.
Definition: qpainter.cpp:2168
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
QRect rect() const
bool isEnabled() const
Definition: qwidget.h:948
QIcon icon
the icon of the header
Definition: qstyleoption.h:265
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
SectionPosition position
the section&#39;s position in relation to the other sections
Definition: qstyleoption.h:267
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
Qt::Alignment iconAlignment
the alignment flags for the icon of the header
Definition: qstyleoption.h:266
SelectedPosition selectedPosition
the section&#39;s position in relation to the selected section
Definition: qstyleoption.h:268
State
Definition: qaudio.h:59
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
int count() const
Returns the number of sections in the header.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
State state() const
Returns the item view&#39;s state.
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
int section
which section of the header is being painted
Definition: qstyleoption.h:262
const char * variant
bool isSortIndicatorShown() const
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
Qt::SortOrder sortIndicatorOrder() const
Returns the order for the sort indicator.
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ reset()

void QHeaderView::reset ( )
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1662 of file qheaderview.cpp.

1663 {
1665  // it would be correct to call clear, but some apps rely
1666  // on the header keeping the sections, even after calling reset
1667  //d->clear();
1669 }
virtual void reset()
Reset the internal state of the view.
void initializeSections()

◆ resizeMode()

QHeaderView::ResizeMode QHeaderView::resizeMode ( int  logicalIndex) const

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

See also
setResizeMode()

Definition at line 1284 of file qheaderview.cpp.

Referenced by dataChanged(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), QHeaderViewPrivate::resizeSections(), QHeaderViewPrivate::setGlobalHeaderResizeMode(), and setSortIndicator().

1285 {
1286  Q_D(const QHeaderView);
1287  int visual = visualIndex(logicalIndex);
1288  if (visual == -1)
1289  return Fixed; //the default value
1290  return d->headerSectionResizeMode(visual);
1291 }
double d
Definition: qnumeric_p.h:62
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
#define Q_D(Class)
Definition: qglobal.h:2482
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ resizeSection()

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

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

See also
sectionResized(), resizeMode(), sectionSize()

Definition at line 927 of file qheaderview.cpp.

Referenced by QFileDialogPrivate::createWidgets(), mouseMoveEvent(), setSectionHidden(), and setStretchLastSection().

928 {
929  Q_D(QHeaderView);
930  if (logical < 0 || logical >= count())
931  return;
932 
933  if (isSectionHidden(logical)) {
934  d->hiddenSectionSize.insert(logical, size);
935  return;
936  }
937 
938  int visual = visualIndex(logical);
939  if (visual == -1)
940  return;
941 
942  int oldSize = d->headerSectionSize(visual);
943  if (oldSize == size)
944  return;
945 
946  d->executePostedLayout();
947  d->invalidateCachedSizeHint();
948 
949  if (stretchLastSection() && visual == d->lastVisibleVisualIndex())
950  d->lastSectionSize = size;
951 
952  if (size != oldSize)
953  d->createSectionSpan(visual, visual, size, d->headerSectionResizeMode(visual));
954 
955  if (!updatesEnabled()) {
956  if (d->hasAutoResizeSections())
957  d->doDelayedResizeSections();
958  emit sectionResized(logical, oldSize, size);
959  return;
960  }
961 
962  int w = d->viewport->width();
963  int h = d->viewport->height();
964  int pos = sectionViewportPosition(logical);
965  QRect r;
966  if (d->orientation == Qt::Horizontal)
967  if (isRightToLeft())
968  r.setRect(0, 0, pos + size, h);
969  else
970  r.setRect(pos, 0, w - pos, h);
971  else
972  r.setRect(0, pos, w, h - pos);
973 
974  if (d->hasAutoResizeSections()) {
975  d->doDelayedResizeSections();
976  r = d->viewport->rect();
977  }
978  d->viewport->update(r.normalized());
979  emit sectionResized(logical, oldSize, size);
980 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
QSize size() const
void sectionResized(int logicalIndex, int oldSize, int newSize)
This signal is emitted when a section is resized.
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
bool updatesEnabled() const
#define Q_D(Class)
Definition: qglobal.h:2482
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
#define emit
Definition: qobjectdefs.h:76
int sectionViewportPosition(int logicalIndex) const
Returns the section viewport position of the given logicalIndex.
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
int count() const
Returns the number of sections in the header.
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isRightToLeft() const
Definition: qwidget.h:428
bool stretchLastSection() const
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ resizeSections() [1/2]

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

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

See also
resizeMode(), sectionResized()

Definition at line 989 of file qheaderview.cpp.

990 {
991  Q_D(QHeaderView);
992  d->resizeSections(mode, true);
993 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ resizeSections [2/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 1732 of file qheaderview.cpp.

Referenced by event(), setSortIndicator(), setSortIndicatorShown(), setStretchLastSection(), and viewportEvent().

1733 {
1734  Q_D(QHeaderView);
1735  if (d->hasAutoResizeSections())
1736  d->resizeSections(Interactive, false); // no global resize mode
1737 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ restoreState()

bool QHeaderView::restoreState ( const QByteArray state)

Restores the state of this header view.

Since
4.3

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

See also
saveState()

Definition at line 1634 of file qheaderview.cpp.

Referenced by QFileDialog::restoreState().

1635 {
1636  Q_D(QHeaderView);
1637  if (state.isEmpty())
1638  return false;
1639  QByteArray data = state;
1641  int marker;
1642  int ver;
1643  stream >> marker;
1644  stream >> ver;
1645  if (stream.status() != QDataStream::Ok
1647  || ver != 0) // current version is 0
1648  return false;
1649 
1650  if (d->read(stream)) {
1651  emit sortIndicatorChanged(d->sortIndicatorSection, d->sortIndicatorOrder );
1652  d->viewport->update();
1653  return true;
1654  }
1655  return false;
1656 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_D(Class)
Definition: qglobal.h:2482
static FILE * stream
#define emit
Definition: qobjectdefs.h:76
QWidgetData * data
Definition: qwidget.h:815
State state() const
Returns the item view&#39;s state.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ rowsInserted()

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

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

Reimplemented Function

Warning
This function is not part of the public interface.

Reimplemented from QAbstractItemView.

Definition at line 2785 of file qheaderview.cpp.

Referenced by setModel().

2786 {
2787  // do nothing
2788 }

◆ saveState()

QByteArray QHeaderView::saveState ( ) const

Saves the current state of this header view.

Since
4.3

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

See also
restoreState()

Definition at line 1612 of file qheaderview.cpp.

1613 {
1614  Q_D(const QHeaderView);
1615  QByteArray data;
1618  stream << 0; // current version is 0
1619  d->write(stream);
1620  return data;
1621 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_D(Class)
Definition: qglobal.h:2482
static FILE * stream
QWidgetData * data
Definition: qwidget.h:815
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ scrollContentsBy()

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

Reimplemented Function

Warning
This function is not part of the public interface.

Reimplemented from QAbstractScrollArea.

Definition at line 2751 of file qheaderview.cpp.

2752 {
2753  Q_D(QHeaderView);
2754  d->scrollDirtyRegion(dx, dy);
2755 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ scrollTo()

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

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

Reimplemented Function

Warning
This function is not part of the public interface.

Implements QAbstractItemView.

Definition at line 2815 of file qheaderview.cpp.

2816 {
2817  // do nothing - the header only displays sections
2818 }

◆ sectionAutoResize

void QHeaderView::sectionAutoResize ( int  logicalIndex,
QHeaderView::ResizeMode  mode 
)
signal

◆ 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
setClickable(), sectionPressed()

Referenced by mouseReleaseEvent().

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

Referenced by QHeaderViewPrivate::_q_layoutChanged(), initializeSections(), and sectionsInserted().

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

Referenced by mouseDoubleClickEvent().

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

Since
4.3

The section's logical index is specified by logicalIndex.

See also
setClickable(), sectionPressed()

Referenced by mouseMoveEvent().

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

Referenced by mouseDoubleClickEvent().

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

Referenced by moveSection(), and swapSections().

◆ 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 709 of file qheaderview.cpp.

Referenced by QTreeView::drawRow(), QAccessibleHeader::rect(), QAccessibleTable2HeaderCell::rect(), QTableViewPrivate::sectionSpanSize(), and sectionViewportPosition().

710 {
711  Q_D(const QHeaderView);
712  int visual = visualIndex(logicalIndex);
713  // in some cases users may change the selections
714  // before we have a chance to do the layout
715  if (visual == -1)
716  return -1;
717  d->executePostedResize();
718  return d->headerSectionPosition(visual);
719 }
double d
Definition: qnumeric_p.h:62
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
#define Q_D(Class)
Definition: qglobal.h:2482
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

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

Referenced by mousePressEvent().

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

Referenced by QHeaderViewPrivate::cascadingResize(), and resizeSection().

◆ 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 1852 of file qheaderview.cpp.

Referenced by setModel().

1854 {
1855  Q_UNUSED(parent);
1856  Q_UNUSED(logicalFirst);
1857  Q_UNUSED(logicalLast);
1858 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ sectionsHidden()

bool QHeaderView::sectionsHidden ( ) const
Since
4.1

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

See also
setSectionHidden()

Definition at line 1593 of file qheaderview.cpp.

Referenced by QAccessibleItemRow::logicalFromChild(), and QTableView::paintEvent().

1594 {
1595  Q_D(const QHeaderView);
1596  return !d->hiddenSectionSize.isEmpty();
1597 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 1748 of file qheaderview.cpp.

Referenced by setModel().

1750 {
1751  Q_D(QHeaderView);
1752  if (parent != d->root)
1753  return; // we only handle changes in the top level
1754  int oldCount = d->sectionCount;
1755 
1756  d->invalidateCachedSizeHint();
1757 
1758  // add the new sections
1759  int insertAt = 0;
1760  for (int spanStart = 0; insertAt < d->sectionSpans.count() && spanStart < logicalFirst; ++insertAt)
1761  spanStart += d->sectionSpans.at(insertAt).count;
1762 
1763  int insertCount = logicalLast - logicalFirst + 1;
1764  d->sectionCount += insertCount;
1765 
1766  if (d->sectionSpans.isEmpty() || insertAt >= d->sectionSpans.count()) {
1767  int insertLength = d->defaultSectionSize * insertCount;
1768  d->length += insertLength;
1769  QHeaderViewPrivate::SectionSpan span(insertLength, insertCount, d->globalResizeMode);
1770  d->sectionSpans.append(span);
1771  } else if ((d->sectionSpans.at(insertAt).sectionSize() == d->defaultSectionSize)
1772  && d->sectionSpans.at(insertAt).resizeMode == d->globalResizeMode) {
1773  // add the new sections to an existing span
1774  int insertLength = d->sectionSpans.at(insertAt).sectionSize() * insertCount;
1775  d->length += insertLength;
1776  d->sectionSpans[insertAt].size += insertLength;
1777  d->sectionSpans[insertAt].count += insertCount;
1778  } else {
1779  // separate them out into their own span
1780  int insertLength = d->defaultSectionSize * insertCount;
1781  d->length += insertLength;
1782  QHeaderViewPrivate::SectionSpan span(insertLength, insertCount, d->globalResizeMode);
1783  d->sectionSpans.insert(insertAt, span);
1784  }
1785 
1786  // update sorting column
1787  if (d->sortIndicatorSection >= logicalFirst)
1788  d->sortIndicatorSection += insertCount;
1789 
1790  // update resize mode section counts
1791  if (d->globalResizeMode == Stretch)
1792  d->stretchSections = d->sectionCount;
1793  else if (d->globalResizeMode == ResizeToContents)
1794  d->contentsSections = d->sectionCount;
1795 
1796  // clear selection cache
1797  d->sectionSelected.clear();
1798 
1799  // update mapping
1800  if (!d->visualIndices.isEmpty() && !d->logicalIndices.isEmpty()) {
1801  Q_ASSERT(d->visualIndices.count() == d->logicalIndices.count());
1802  int mappingCount = d->visualIndices.count();
1803  for (int i = 0; i < mappingCount; ++i) {
1804  if (d->visualIndices.at(i) >= logicalFirst)
1805  d->visualIndices[i] += insertCount;
1806  if (d->logicalIndices.at(i) >= logicalFirst)
1807  d->logicalIndices[i] += insertCount;
1808  }
1809  for (int j = logicalFirst; j <= logicalLast; ++j) {
1810  d->visualIndices.insert(j, j);
1811  d->logicalIndices.insert(j, j);
1812  }
1813  }
1814 
1815  // insert sections into sectionsHidden
1816  if (!d->sectionHidden.isEmpty()) {
1817  QBitArray sectionHidden(d->sectionHidden);
1818  sectionHidden.resize(sectionHidden.count() + insertCount);
1819  sectionHidden.fill(false, logicalFirst, logicalLast + 1);
1820  for (int j = logicalLast + 1; j < sectionHidden.count(); ++j)
1821  //here we simply copy the old sectionHidden
1822  sectionHidden.setBit(j, d->sectionHidden.testBit(j - insertCount));
1823  d->sectionHidden = sectionHidden;
1824  }
1825 
1826  // insert sections into hiddenSectionSize
1827  QHash<int, int> newHiddenSectionSize; // from logical index to section size
1828  for (int i = 0; i < logicalFirst; ++i)
1829  if (isSectionHidden(i))
1830  newHiddenSectionSize[i] = d->hiddenSectionSize[i];
1831  for (int j = logicalLast + 1; j < d->sectionCount; ++j)
1832  if (isSectionHidden(j))
1833  newHiddenSectionSize[j] = d->hiddenSectionSize[j - insertCount];
1834  d->hiddenSectionSize = newHiddenSectionSize;
1835 
1836  d->doDelayedResizeSections();
1837  emit sectionCountChanged(oldCount, count());
1838 
1839  // if the new sections were not updated by resizing, we need to update now
1840  if (!d->hasAutoResizeSections())
1841  d->viewport->update();
1842 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
void sectionCountChanged(int oldCount, int newCount)
This signal is emitted when the number of sections changes, i.
for(int ii=mo->methodOffset();ii< mo->methodCount();++ii)
#define emit
Definition: qobjectdefs.h:76
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
int count() const
Returns the number of sections in the header.
if(void) toggleToolbarShown
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ sectionSize()

int QHeaderView::sectionSize ( int  logicalIndex) const

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

See also
length(), setResizeMode(), defaultSectionSize()

Definition at line 684 of file qheaderview.cpp.

Referenced by QHeaderViewPrivate::cascadingResize(), currentChanged(), QTreeView::drawRow(), initializeSections(), QTreeViewPrivate::itemDecorationRect(), mousePressEvent(), moveSection(), QTableView::paintEvent(), paintEvent(), QAccessibleHeader::rect(), QAccessibleTable2HeaderCell::rect(), QHeaderViewPrivate::resizeSections(), QTableViewPrivate::sectionSpanSize(), sectionViewportPosition(), QTreeViewPrivate::updateScrollBars(), updateSection(), and visualRegionForSelection().

685 {
686  Q_D(const QHeaderView);
688  return 0;
689  if (logicalIndex < 0 || logicalIndex >= count())
690  return 0;
691  int visual = visualIndex(logicalIndex);
692  if (visual == -1)
693  return 0;
694  d->executePostedResize();
695  return d->headerSectionSize(visual);
696 }
double d
Definition: qnumeric_p.h:62
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
int count() const
Returns the number of sections in the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 2661 of file qheaderview.cpp.

Referenced by sectionSizeHint(), and sizeHint().

2662 {
2663  Q_D(const QHeaderView);
2664  Q_ASSERT(logicalIndex >= 0);
2665 
2666  ensurePolished();
2667 
2668  // use SizeHintRole
2669  QVariant variant = d->model->headerData(logicalIndex, d->orientation, Qt::SizeHintRole);
2670  if (variant.isValid())
2671  return qvariant_cast<QSize>(variant);
2672 
2673  // otherwise use the contents
2674  QStyleOptionHeader opt;
2675  initStyleOption(&opt);
2676  opt.section = logicalIndex;
2677  QVariant var = d->model->headerData(logicalIndex, d->orientation,
2678  Qt::FontRole);
2679  QFont fnt;
2680  if (var.isValid() && var.canConvert<QFont>())
2681  fnt = qvariant_cast<QFont>(var);
2682  else
2683  fnt = font();
2684  fnt.setBold(true);
2685  opt.fontMetrics = QFontMetrics(fnt);
2686  opt.text = d->model->headerData(logicalIndex, d->orientation,
2687  Qt::DisplayRole).toString();
2688  variant = d->model->headerData(logicalIndex, d->orientation, Qt::DecorationRole);
2689  opt.icon = qvariant_cast<QIcon>(variant);
2690  if (opt.icon.isNull())
2691  opt.icon = qvariant_cast<QPixmap>(variant);
2693  if (isSortIndicatorShown()) {
2694  int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this);
2695  if (d->orientation == Qt::Horizontal)
2696  size.rwidth() += size.height() + margin;
2697  else
2698  size.rheight() += size.width() + margin;
2699  }
2700  return size;
2701 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QSize size() const
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:251
void initStyleOption(QStyleOptionHeader *option) const
Initialize option with the values from this QHeaderView.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
friend class QFontMetrics
Definition: qwidget.h:749
QString text
the text of the header
Definition: qstyleoption.h:263
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
int width() const
Returns the width.
Definition: qsize.h:126
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
QIcon icon
the icon of the header
Definition: qstyleoption.h:265
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
int height() const
Returns the height.
Definition: qsize.h:129
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
const QFont & font() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int section
which section of the header is being painted
Definition: qstyleoption.h:262
const char * variant
bool isSortIndicatorShown() const
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ sectionSizeHint()

int QHeaderView::sectionSizeHint ( int  logicalIndex) const

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

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

Definition at line 611 of file qheaderview.cpp.

612 {
613  Q_D(const QHeaderView);
615  return 0;
616  if (logicalIndex < 0 || logicalIndex >= count())
617  return -1;
618  QSize size;
619  QVariant value = d->model->headerData(logicalIndex, d->orientation, Qt::SizeHintRole);
620  if (value.isValid())
621  size = qvariant_cast<QSize>(value);
622  else
624  int hint = d->orientation == Qt::Horizontal ? size.width() : size.height();
625  return qMax(minimumSectionSize(), hint);
626 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QSize size() const
int minimumSectionSize() const
#define Q_D(Class)
Definition: qglobal.h:2482
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int width() const
Returns the width.
Definition: qsize.h:126
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
int count() const
Returns the number of sections in the header.
int height() const
Returns the height.
Definition: qsize.h:129
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
virtual QSize sectionSizeFromContents(int logicalIndex) const
Returns the size of the contents of the section specified by the given logicalIndex.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ sectionsMoved()

bool QHeaderView::sectionsMoved ( ) const

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

See also
moveSection()

Definition at line 1579 of file qheaderview.cpp.

Referenced by QTreeView::drawRow(), QTableViewPrivate::selectColumn(), QTableViewPrivate::selectRow(), QTableView::setSelection(), and QTableView::visualRegionForSelection().

1580 {
1581  Q_D(const QHeaderView);
1582  return !d->visualIndices.isEmpty();
1583 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 729 of file qheaderview.cpp.

Referenced by currentChanged(), QTreeViewPrivate::itemDecorationRect(), paintEvent(), resizeSection(), updateSection(), and visualRegionForSelection().

730 {
731  Q_D(const QHeaderView);
732  if (logicalIndex >= count())
733  return -1;
735  if (position < 0)
736  return position; // the section was hidden
737  int offsetPosition = position - d->offset;
738  if (d->reverse())
739  return d->viewport->width() - (offsetPosition + sectionSize(logicalIndex));
740  return offsetPosition;
741 }
double d
Definition: qnumeric_p.h:62
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
#define Q_D(Class)
Definition: qglobal.h:2482
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
int count() const
Returns the number of sections in the header.
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.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setCascadingSectionResizes()

void QHeaderView::setCascadingSectionResizes ( bool  enable)

Definition at line 1473 of file qheaderview.cpp.

1474 {
1475  Q_D(QHeaderView);
1476  d->cascadingResizing = enable;
1477 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setClickable()

void QHeaderView::setClickable ( bool  clickable)

If clickable is true, the header will respond to single clicks.

See also
isClickable(), sectionClicked(), sectionPressed(), setSortIndicatorShown()

Definition at line 1186 of file qheaderview.cpp.

Referenced by QTableViewPrivate::init(), QTreeWidget::QTreeWidget(), and QTreeView::setSortingEnabled().

1187 {
1188  Q_D(QHeaderView);
1189  d->clickableSections = clickable;
1190 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setDefaultAlignment()

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

Definition at line 1554 of file qheaderview.cpp.

Referenced by QTreeViewPrivate::initialize().

1555 {
1556  Q_D(QHeaderView);
1557  if (d->defaultAlignment == alignment)
1558  return;
1559 
1560  d->defaultAlignment = alignment;
1561  d->viewport->update();
1562 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setDefaultSectionSize()

void QHeaderView::setDefaultSectionSize ( int  size)

Definition at line 1497 of file qheaderview.cpp.

1498 {
1499  Q_D(QHeaderView);
1500  d->setDefaultSectionSize(size);
1501 }
double d
Definition: qnumeric_p.h:62
QSize size() const
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setHighlightSections()

void QHeaderView::setHighlightSections ( bool  highlight)

Definition at line 1207 of file qheaderview.cpp.

Referenced by QTableViewPrivate::init().

1208 {
1209  Q_D(QHeaderView);
1210  d->highlightSelected = highlight;
1211 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setMinimumSectionSize()

void QHeaderView::setMinimumSectionSize ( int  size)

Definition at line 1533 of file qheaderview.cpp.

1534 {
1535  Q_D(QHeaderView);
1536  d->minimumSectionSize = size;
1537 }
double d
Definition: qnumeric_p.h:62
QSize size() const
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setModel()

void QHeaderView::setModel ( QAbstractItemModel model)
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 402 of file qheaderview.cpp.

403 {
404  if (model == this->model())
405  return;
406  Q_D(QHeaderView);
407  if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
408  if (d->orientation == Qt::Horizontal) {
409  QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
410  this, SLOT(sectionsInserted(QModelIndex,int,int)));
411  QObject::disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
412  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
413  QObject::disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
414  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
415  } else {
417  this, SLOT(sectionsInserted(QModelIndex,int,int)));
419  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
420  QObject::disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
421  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
422  }
424  this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
425  QObject::disconnect(d->model, SIGNAL(layoutAboutToBeChanged()),
426  this, SLOT(_q_layoutAboutToBeChanged()));
427  }
428 
429  if (model && model != QAbstractItemModelPrivate::staticEmptyModel()) {
430  if (d->orientation == Qt::Horizontal) {
431  QObject::connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)),
432  this, SLOT(sectionsInserted(QModelIndex,int,int)));
433  QObject::connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
434  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
435  QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
436  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
437  } else {
439  this, SLOT(sectionsInserted(QModelIndex,int,int)));
441  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
442  QObject::connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
443  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
444  }
446  this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
447  QObject::connect(model, SIGNAL(layoutAboutToBeChanged()),
448  this, SLOT(_q_layoutAboutToBeChanged()));
449  }
450 
454 
455  // Users want to set sizes and modes before the widget is shown.
456  // Thus, we have to initialize when the model is set,
457  // and not lazily like we do in the other views.
459 }
double d
Definition: qnumeric_p.h:62
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
static QAbstractItemModel * staticEmptyModel()
void rowsInserted(const QModelIndex &parent, int start, int end)
Empty implementation because the header doesn&#39;t show QModelIndex items.
#define SLOT(a)
Definition: qobjectdefs.h:226
void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast)
This slot is called when sections are removed from the parent.
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void initializeSections()
void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast)
Updates the changed header sections with the given orientation, from logicalFirst to logicalLast incl...
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
The QModelIndex class is used to locate data in a data model.
void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast)
This slot is called when sections are inserted into the parent.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
Orientation
Definition: qnamespace.h:174
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setMovable()

void QHeaderView::setMovable ( bool  movable)

If movable is true, the header may be moved by the user; otherwise it is fixed in place.

See also
isMovable(), sectionMoved()

Definition at line 1158 of file qheaderview.cpp.

Referenced by QTreeViewPrivate::initialize().

1159 {
1160  Q_D(QHeaderView);
1161  d->movableSections = movable;
1162 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setOffset

void QHeaderView::setOffset ( int  offset)
slot

Sets the header's offset to offset.

See also
offset(), length()

Definition at line 497 of file qheaderview.cpp.

Referenced by setOffsetToLastSection(), and setOffsetToSectionPosition().

498 {
499  Q_D(QHeaderView);
500  if (d->offset == (int)newOffset)
501  return;
502  int ndelta = d->offset - newOffset;
503  d->offset = newOffset;
504  if (d->orientation == Qt::Horizontal)
505  d->viewport->scroll(isRightToLeft() ? -ndelta : ndelta, 0);
506  else
507  d->viewport->scroll(0, ndelta);
508  if (d->state == QHeaderViewPrivate::ResizeSection) {
509  QPoint cursorPos = QCursor::pos();
510  if (d->orientation == Qt::Horizontal)
511  QCursor::setPos(cursorPos.x() + ndelta, cursorPos.y());
512  else
513  QCursor::setPos(cursorPos.x(), cursorPos.y() + ndelta);
514  d->firstPos += ndelta;
515  d->lastPos += ndelta;
516  }
517 }
double d
Definition: qnumeric_p.h:62
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
#define Q_D(Class)
Definition: qglobal.h:2482
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
bool isRightToLeft() const
Definition: qwidget.h:428
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setOffsetToLastSection

void QHeaderView::setOffsetToLastSection ( )
slot

Sets the offset to make the last section visible.

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

Definition at line 546 of file qheaderview.cpp.

547 {
548  Q_D(const QHeaderView);
549  int size = (d->orientation == Qt::Horizontal ? viewport()->width() : viewport()->height());
550  int position = length() - size;
551  setOffset(position);
552 }
double d
Definition: qnumeric_p.h:62
void setOffset(int offset)
Sets the header&#39;s offset to offset.
QSize size() const
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
int length() const
Returns the length along the orientation of the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setOffsetToSectionPosition

void QHeaderView::setOffsetToSectionPosition ( int  visualIndex)
slot

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

Since
4.2
See also
setOffset(), sectionPosition()

Definition at line 528 of file qheaderview.cpp.

529 {
530  Q_D(QHeaderView);
531  if (visualIndex > -1 && visualIndex < d->sectionCount) {
532  int position = d->headerSectionPosition(d->adjustedVisualIndex(visualIndex));
533  setOffset(position);
534  }
535 }
double d
Definition: qnumeric_p.h:62
void setOffset(int offset)
Sets the header&#39;s offset to offset.
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setResizeMode() [1/2]

void QHeaderView::setResizeMode ( ResizeMode  mode)

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

See also
resizeMode(), length(), sectionResized(), sectionAutoResize()

Definition at line 1226 of file qheaderview.cpp.

1227 {
1228  Q_D(QHeaderView);
1230  d->stretchSections = (mode == Stretch ? count() : 0);
1231  d->contentsSections = (mode == ResizeToContents ? count() : 0);
1232  d->setGlobalHeaderResizeMode(mode);
1233  if (d->hasAutoResizeSections())
1234  d->doDelayedResizeSections(); // section sizes may change as a result of the new mode
1235 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void initializeSections()
int count() const
Returns the number of sections in the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setResizeMode() [2/2]

void QHeaderView::setResizeMode ( int  logicalIndex,
ResizeMode  mode 
)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 1255 of file qheaderview.cpp.

1256 {
1257  Q_D(QHeaderView);
1258  int visual = visualIndex(logicalIndex);
1259  Q_ASSERT(visual != -1);
1260 
1261  ResizeMode old = d->headerSectionResizeMode(visual);
1262  d->setHeaderSectionResizeMode(visual, mode);
1263 
1264  if (mode == Stretch && old != Stretch)
1265  ++d->stretchSections;
1266  else if (mode == ResizeToContents && old != ResizeToContents)
1267  ++d->contentsSections;
1268  else if (mode != Stretch && old == Stretch)
1269  --d->stretchSections;
1270  else if (mode != ResizeToContents && old == ResizeToContents)
1271  --d->contentsSections;
1272 
1273  if (d->hasAutoResizeSections() && d->state == QHeaderViewPrivate::NoState)
1274  d->doDelayedResizeSections(); // section sizes may change as a result of the new mode
1275 }
double d
Definition: qnumeric_p.h:62
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
ResizeMode
The resize mode specifies the behavior of the header sections.
Definition: qheaderview.h:72
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 1058 of file qheaderview.cpp.

1059 {
1060  Q_D(QHeaderView);
1061  if (logicalIndex < 0 || logicalIndex >= count())
1062  return;
1063 
1064  d->executePostedLayout();
1065  int visual = visualIndex(logicalIndex);
1066  Q_ASSERT(visual != -1);
1067  if (hide == d->isVisualIndexHidden(visual))
1068  return;
1069  if (hide) {
1070  int size = d->headerSectionSize(visual);
1071  if (!d->hasAutoResizeSections())
1073  d->hiddenSectionSize.insert(logicalIndex, size);
1074  if (d->sectionHidden.count() < count())
1075  d->sectionHidden.resize(count());
1076  d->sectionHidden.setBit(visual, true);
1077  if (d->hasAutoResizeSections())
1078  d->doDelayedResizeSections();
1079  } else {
1080  int size = d->hiddenSectionSize.value(logicalIndex, d->defaultSectionSize);
1081  d->hiddenSectionSize.remove(logicalIndex);
1082  if (d->hiddenSectionSize.isEmpty()) {
1083  d->sectionHidden.clear();
1084  } else {
1085  Q_ASSERT(visual <= d->sectionHidden.count());
1086  d->sectionHidden.setBit(visual, false);
1087  }
1088  resizeSection(logicalIndex, size);
1089  }
1090 }
double d
Definition: qnumeric_p.h:62
QSize size() const
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
void resizeSection(int logicalIndex, int size)
Resizes the section specified by logicalIndex to size measured in pixels.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void hide()
Hides the widget.
Definition: qwidget.h:501
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
int count() const
Returns the number of sections in the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setSelection()

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

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

Reimplemented Function

The base class implementation does nothing.

Implements QAbstractItemView.

Definition at line 2877 of file qheaderview.cpp.

2878 {
2879  // do nothing
2880 }

◆ 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 1359 of file qheaderview.cpp.

Referenced by QFileDialogTreeView::init(), QTableWidget::sortItems(), and QTreeWidget::sortItems().

1360 {
1361  Q_D(QHeaderView);
1362 
1363  // This is so that people can set the position of the sort indicator before the fill the model
1364  int old = d->sortIndicatorSection;
1365  d->sortIndicatorSection = logicalIndex;
1366  d->sortIndicatorOrder = order;
1367 
1368  if (logicalIndex >= d->sectionCount) {
1370  return; // nothing to do
1371  }
1372 
1373  if (old != logicalIndex
1375  || old >= d->sectionCount || (old >= 0 && resizeMode(old) == ResizeToContents))) {
1376  resizeSections();
1377  d->viewport->update();
1378  } else {
1379  if (old >= 0 && old != logicalIndex)
1380  updateSection(old);
1381  if (logicalIndex >= 0)
1383  }
1384 
1386 }
double d
Definition: qnumeric_p.h:62
void resizeSections()
Resizes the sections according to their size hints.
ResizeMode resizeMode(int logicalIndex) const
Returns the resize mode that applies to the section specified by the given logicalIndex.
#define Q_D(Class)
Definition: qglobal.h:2482
void updateSection(int logicalIndex)
Updates the section specified by the given logicalIndex.
#define emit
Definition: qobjectdefs.h:76
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setSortIndicatorShown()

void QHeaderView::setSortIndicatorShown ( bool  show)

Definition at line 1324 of file qheaderview.cpp.

Referenced by QTableView::setSortingEnabled(), and QTreeView::setSortingEnabled().

1325 {
1326  Q_D(QHeaderView);
1327  if (d->sortIndicatorShown == show)
1328  return;
1329 
1330  d->sortIndicatorShown = show;
1331 
1332  if (sortIndicatorSection() < 0 || sortIndicatorSection() > count())
1333  return;
1334 
1335  if (d->headerSectionResizeMode(sortIndicatorSection()) == ResizeToContents)
1336  resizeSections();
1337 
1338  d->viewport->update();
1339 }
double d
Definition: qnumeric_p.h:62
void resizeSections()
Resizes the sections according to their size hints.
int sortIndicatorSection() const
Returns the logical index of the section that has a sort indicator.
#define Q_D(Class)
Definition: qglobal.h:2482
void show()
Shows the widget and its child widgets.
int count() const
Returns the number of sections in the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ setStretchLastSection()

void QHeaderView::setStretchLastSection ( bool  stretch)

Definition at line 1438 of file qheaderview.cpp.

Referenced by QFileDialogTreeView::init(), and QTreeViewPrivate::initialize().

1439 {
1440  Q_D(QHeaderView);
1441  d->stretchLastSection = stretch;
1442  if (d->state != QHeaderViewPrivate::NoState)
1443  return;
1444  if (stretch)
1445  resizeSections();
1446  else if (count())
1447  resizeSection(count() - 1, d->defaultSectionSize);
1448 }
double d
Definition: qnumeric_p.h:62
void resizeSections()
Resizes the sections according to their size hints.
void resizeSection(int logicalIndex, int size)
Resizes the section specified by logicalIndex to size measured in pixels.
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
Returns the number of sections in the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ showSection()

void QHeaderView::showSection ( int  logicalIndex)
inline

Shows the section specified by logicalIndex.

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

Definition at line 241 of file qheaderview.h.

242 { setSectionHidden(alogicalIndex, false); }
void setSectionHidden(int logicalIndex, bool hide)
If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown...

◆ sizeHint()

QSize QHeaderView::sizeHint ( ) const
virtual

Returns a suitable size hint for this header.

See also
sectionSizeHint()

Reimplemented from QWidget.

Definition at line 575 of file qheaderview.cpp.

Referenced by QFileDialogTreeView::sizeHint().

576 {
577  Q_D(const QHeaderView);
578  if (d->cachedSizeHint.isValid())
579  return d->cachedSizeHint;
580  d->cachedSizeHint = QSize(0, 0); //reinitialize the cached size hint
581  const int sectionCount = count();
582 
583  // get size hint for the first n sections
584  int i = 0;
585  for (int checked = 0; checked < 100 && i < sectionCount; ++i) {
586  if (isSectionHidden(i))
587  continue;
588  checked++;
589  QSize hint = sectionSizeFromContents(i);
590  d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint);
591  }
592  // get size hint for the last n sections
593  i = qMax(i, sectionCount - 100 );
594  for (int j = sectionCount - 1, checked = 0; j >= i && checked < 100; --j) {
595  if (isSectionHidden(j))
596  continue;
597  checked++;
598  QSize hint = sectionSizeFromContents(j);
599  d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint);
600  }
601  return d->cachedSizeHint;
602 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int count() const
Returns the number of sections in the header.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
virtual QSize sectionSizeFromContents(int logicalIndex) const
Returns the size of the contents of the section specified by the given logicalIndex.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ sortIndicatorChanged

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

Referenced by restoreState(), and setSortIndicator().

◆ 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 1408 of file qheaderview.cpp.

Referenced by QTreeModel::executePendingSort(), QHeaderViewPrivate::flipSortIndicator(), paintSection(), QHeaderViewPrivate::read(), QTableModel::setItem(), and QHeaderViewPrivate::write().

1409 {
1410  Q_D(const QHeaderView);
1411  return d->sortIndicatorOrder;
1412 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 1395 of file qheaderview.cpp.

Referenced by QHeaderViewPrivate::_q_sectionsRemoved(), QTreeModel::executePendingSort(), QHeaderViewPrivate::flipSortIndicator(), paintSection(), QHeaderViewPrivate::read(), QTableModel::setItem(), setSortIndicatorShown(), and QHeaderViewPrivate::write().

1396 {
1397  Q_D(const QHeaderView);
1398  return d->sortIndicatorSection;
1399 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ stretchLastSection()

bool QHeaderView::stretchLastSection ( ) const

◆ stretchSectionCount()

int QHeaderView::stretchSectionCount ( ) const

Returns the number of sections that are set to resize mode stretch.

Since
4.1

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

Definition at line 1306 of file qheaderview.cpp.

1307 {
1308  Q_D(const QHeaderView);
1309  return d->stretchSections;
1310 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ swapSections()

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

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

Since
4.2
See also
moveSection()

Definition at line 874 of file qheaderview.cpp.

875 {
876  Q_D(QHeaderView);
877 
878  if (first == second)
879  return;
880  d->executePostedLayout();
881  if (first < 0 || first >= d->sectionCount || second < 0 || second >= d->sectionCount)
882  return;
883 
884  int firstSize = d->headerSectionSize(first);
885  ResizeMode firstMode = d->headerSectionResizeMode(first);
886  int firstLogical = d->logicalIndex(first);
887 
888  int secondSize = d->headerSectionSize(second);
889  ResizeMode secondMode = d->headerSectionResizeMode(second);
890  int secondLogical = d->logicalIndex(second);
891 
892  d->createSectionSpan(second, second, firstSize, firstMode);
893  d->createSectionSpan(first, first, secondSize, secondMode);
894 
895  d->initializeIndexMapping();
896 
897  d->visualIndices[firstLogical] = second;
898  d->logicalIndices[second] = firstLogical;
899 
900  d->visualIndices[secondLogical] = first;
901  d->logicalIndices[first] = secondLogical;
902 
903  if (!d->sectionHidden.isEmpty()) {
904  bool firstHidden = d->sectionHidden.testBit(first);
905  bool secondHidden = d->sectionHidden.testBit(second);
906  d->sectionHidden.setBit(first, secondHidden);
907  d->sectionHidden.setBit(second, firstHidden);
908  }
909 
910  d->viewport->update();
911  emit sectionMoved(firstLogical, first, second);
912  emit sectionMoved(secondLogical, second, first);
913 }
void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex)
This signal is emitted when a section is moved.
double d
Definition: qnumeric_p.h:62
ResizeMode
The resize mode specifies the behavior of the header sections.
Definition: qheaderview.h:72
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ updateGeometries()

void QHeaderView::updateGeometries ( )
protectedvirtual

Reimplemented Function

Warning
This function is not part of the public interface.

Reimplemented from QAbstractItemView.

Definition at line 2738 of file qheaderview.cpp.

2739 {
2740  Q_D(QHeaderView);
2741  d->layoutChildren();
2742  if (d->hasAutoResizeSections())
2743  d->doDelayedResizeSections();
2744 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ updateSection

void QHeaderView::updateSection ( int  logicalIndex)
protectedslot

Updates the section specified by the given logicalIndex.

Warning
This function is not part of the public interface.
Since
4.2

Definition at line 1716 of file qheaderview.cpp.

Referenced by event(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), moveSection(), and setSortIndicator().

1717 {
1718  Q_D(QHeaderView);
1719  if (d->orientation == Qt::Horizontal)
1720  d->viewport->update(QRect(sectionViewportPosition(logicalIndex),
1721  0, sectionSize(logicalIndex), d->viewport->height()));
1722  else
1723  d->viewport->update(QRect(0, sectionViewportPosition(logicalIndex),
1724  d->viewport->width(), sectionSize(logicalIndex)));
1725 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int sectionViewportPosition(int logicalIndex) const
Returns the section viewport position of the given logicalIndex.
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ verticalOffset()

int QHeaderView::verticalOffset ( ) const
protectedvirtual

Returns the vertical offset of the header.

This is 0 for horizontal headers.

See also
offset()

Implements QAbstractItemView.

Definition at line 2725 of file qheaderview.cpp.

2726 {
2727  Q_D(const QHeaderView);
2728  if (d->orientation == Qt::Vertical)
2729  return d->offset;
2730  return 0;
2731 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ viewportEvent()

bool QHeaderView::viewportEvent ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2479 of file qheaderview.cpp.

2480 {
2481  Q_D(QHeaderView);
2482  switch (e->type()) {
2483 #ifndef QT_NO_TOOLTIP
2484  case QEvent::ToolTip: {
2485  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2486  int logical = logicalIndexAt(he->pos());
2487  if (logical != -1) {
2488  QVariant variant = d->model->headerData(logical, d->orientation, Qt::ToolTipRole);
2489  if (variant.isValid()) {
2490  QToolTip::showText(he->globalPos(), variant.toString(), this);
2491  return true;
2492  }
2493  }
2494  break; }
2495 #endif
2496 #ifndef QT_NO_WHATSTHIS
2497  case QEvent::QueryWhatsThis: {
2498  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2499  int logical = logicalIndexAt(he->pos());
2500  if (logical != -1
2501  && d->model->headerData(logical, d->orientation, Qt::WhatsThisRole).isValid())
2502  return true;
2503  break; }
2504  case QEvent::WhatsThis: {
2505  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2506  int logical = logicalIndexAt(he->pos());
2507  if (logical != -1) {
2508  QVariant whatsthis = d->model->headerData(logical, d->orientation,
2510  if (whatsthis.isValid()) {
2511  QWhatsThis::showText(he->globalPos(), whatsthis.toString(), this);
2512  return true;
2513  }
2514  }
2515  break; }
2516 #endif // QT_NO_WHATSTHIS
2517 #ifndef QT_NO_STATUSTIP
2518  case QEvent::StatusTip: {
2519  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2520  int logical = logicalIndexAt(he->pos());
2521  if (logical != -1) {
2522  QString statustip = d->model->headerData(logical, d->orientation,
2523  Qt::StatusTipRole).toString();
2524  if (!statustip.isEmpty())
2525  setStatusTip(statustip);
2526  }
2527  return true; }
2528 #endif // QT_NO_STATUSTIP
2529  case QEvent::Hide:
2530  case QEvent::Show:
2531  case QEvent::FontChange:
2532  case QEvent::StyleChange:
2533  d->invalidateCachedSizeHint();
2534  resizeSections();
2536  break;
2537  case QEvent::ContextMenu: {
2538  d->state = QHeaderViewPrivate::NoState;
2539  d->pressed = d->section = d->target = -1;
2540  d->updateSectionIndicator(d->section, -1);
2541  break; }
2542  case QEvent::Wheel: {
2544  if (asa)
2545  return QApplication::sendEvent(asa->viewport(), e);
2546  break; }
2547  default:
2548  break;
2549  }
2551 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void resizeSections()
Resizes the sections according to their size hints.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
void setStatusTip(const QString &)
Definition: qwidget.cpp:11629
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
const char * variant
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What&#39;s This?" window, at global position pos.
Definition: qwhatsthis.cpp:754
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
bool viewportEvent(QEvent *event)
This function is used to handle tool tips, and What&#39;s This? mode, if the given event is a QEvent::Too...
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
void geometriesChanged()
This signal is emitted when the header&#39;s geometries have changed.
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition: qevent.h:597

◆ 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 1116 of file qheaderview.cpp.

Referenced by QHeaderViewPrivate::adjustedVisualIndex(), QTreeViewPrivate::adjustViewOptionsForIndex(), QTreeViewPrivate::columnRanges(), QTreeView::drawRow(), headerDataChanged(), isSectionHidden(), mouseMoveEvent(), mouseReleaseEvent(), paintSection(), resizeMode(), resizeSection(), sectionPosition(), sectionSize(), QTableViewPrivate::sectionSpanEndLogical(), setResizeMode(), setSectionHidden(), QTableViewPrivate::spanContainsSection(), QTableWidget::visualColumn(), visualRegionForSelection(), and QTableWidget::visualRow().

1117 {
1118  Q_D(const QHeaderView);
1119  if (logicalIndex < 0)
1120  return -1;
1121  d->executePostedLayout();
1122  if (d->visualIndices.isEmpty()) { // nothing has been moved, so we have no mapping
1123  if (logicalIndex < d->sectionCount)
1124  return logicalIndex;
1125  } else if (logicalIndex < d->visualIndices.count()) {
1126  int visual = d->visualIndices.at(logicalIndex);
1127  Q_ASSERT(visual < d->sectionCount);
1128  return visual;
1129  }
1130  return -1;
1131 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ 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 635 of file qheaderview.cpp.

Referenced by logicalIndexAt(), mouseMoveEvent(), QTableView::paintEvent(), paintEvent(), and QTreeViewPrivate::startAndEndColumns().

636 {
637  Q_D(const QHeaderView);
638  int vposition = position;
639  d->executePostedLayout();
640  d->executePostedResize();
641  const int count = d->sectionCount;
642  if (count < 1)
643  return -1;
644 
645  if (d->reverse())
646  vposition = d->viewport->width() - vposition;
647  vposition += d->offset;
648 
649  if (vposition > d->length)
650  return -1;
651  int visual = d->headerVisualIndexAt(vposition);
652  if (visual < 0)
653  return -1;
654 
655  while (d->isVisualIndexHidden(visual)){
656  ++visual;
657  if (visual >= count)
658  return -1;
659  }
660  return visual;
661 }
double d
Definition: qnumeric_p.h:62
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
Returns the number of sections in the header.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

◆ visualRect()

QRect QHeaderView::visualRect ( const QModelIndex index) const
protectedvirtual

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

Reimplemented Function

Warning
This function is not part of the public interface.

Implements QAbstractItemView.

Definition at line 2800 of file qheaderview.cpp.

2801 {
2802  return QRect();
2803 }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ visualRegionForSelection()

QRegion QHeaderView::visualRegionForSelection ( const QItemSelection selection) const
protectedvirtual
Warning
This function is not part of the public interface.

Implements QAbstractItemView.

Definition at line 2886 of file qheaderview.cpp.

2887 {
2888  Q_D(const QHeaderView);
2889  const int max = d->modelSectionCount();
2890  if (d->orientation == Qt::Horizontal) {
2891  int left = max;
2892  int right = 0;
2893  int rangeLeft, rangeRight;
2894 
2895  for (int i = 0; i < selection.count(); ++i) {
2896  QItemSelectionRange r = selection.at(i);
2897  if (r.parent().isValid() || !r.isValid())
2898  continue; // we only know about toplevel items and we don't want invalid ranges
2899  // FIXME an item inside the range may be the leftmost or rightmost
2900  rangeLeft = visualIndex(r.left());
2901  if (rangeLeft == -1) // in some cases users may change the selections
2902  continue; // before we have a chance to do the layout
2903  rangeRight = visualIndex(r.right());
2904  if (rangeRight == -1) // in some cases users may change the selections
2905  continue; // before we have a chance to do the layout
2906  if (rangeLeft < left)
2907  left = rangeLeft;
2908  if (rangeRight > right)
2909  right = rangeRight;
2910  }
2911 
2912  int logicalLeft = logicalIndex(left);
2913  int logicalRight = logicalIndex(right);
2914 
2915  if (logicalLeft < 0 || logicalLeft >= count() ||
2916  logicalRight < 0 || logicalRight >= count())
2917  return QRegion();
2918 
2919  int leftPos = sectionViewportPosition(logicalLeft);
2920  int rightPos = sectionViewportPosition(logicalRight);
2921  rightPos += sectionSize(logicalRight);
2922  return QRect(leftPos, 0, rightPos - leftPos, height());
2923  }
2924  // orientation() == Qt::Vertical
2925  int top = max;
2926  int bottom = 0;
2927  int rangeTop, rangeBottom;
2928 
2929  for (int i = 0; i < selection.count(); ++i) {
2930  QItemSelectionRange r = selection.at(i);
2931  if (r.parent().isValid() || !r.isValid())
2932  continue; // we only know about toplevel items
2933  // FIXME an item inside the range may be the leftmost or rightmost
2934  rangeTop = visualIndex(r.top());
2935  if (rangeTop == -1) // in some cases users may change the selections
2936  continue; // before we have a chance to do the layout
2937  rangeBottom = visualIndex(r.bottom());
2938  if (rangeBottom == -1) // in some cases users may change the selections
2939  continue; // before we have a chance to do the layout
2940  if (rangeTop < top)
2941  top = rangeTop;
2942  if (rangeBottom > bottom)
2943  bottom = rangeBottom;
2944  }
2945 
2946  int logicalTop = logicalIndex(top);
2947  int logicalBottom = logicalIndex(bottom);
2948 
2949  if (logicalTop == -1 || logicalBottom == -1)
2950  return QRect();
2951 
2952  int topPos = sectionViewportPosition(logicalTop);
2953  int bottomPos = sectionViewportPosition(logicalBottom) + sectionSize(logicalBottom);
2954 
2955  return QRect(0, topPos, width(), bottomPos - topPos);
2956 }
double d
Definition: qnumeric_p.h:62
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
bool isValid() const
Returns true if the selection range is valid; otherwise returns false.
The QItemSelectionRange class manages information about a range of selected items in a model...
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
int width() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
int sectionViewportPosition(int logicalIndex) const
Returns the section viewport position of the given logicalIndex.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
int count() const
Returns the number of sections in the header.
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58

Properties

◆ cascadingSectionResizes

bool QHeaderView::cascadingSectionResizes
private

whether interactive resizing will be cascaded to the following sections once the section being resized by the user has reached its minimum size

Since
4.2

This property only affects sections that have Interactive as their resize mode.

The default value is false.

See also
setResizeMode()

Definition at line 64 of file qheaderview.h.

◆ defaultAlignment

Qt::Alignment QHeaderView::defaultAlignment
private

the default alignment of the text in each header section

Since
4.1

Definition at line 67 of file qheaderview.h.

◆ defaultSectionSize

int QHeaderView::defaultSectionSize
private

the default size of the header sections before resizing.

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

See also
setResizeMode() minimumSectionSize

Definition at line 65 of file qheaderview.h.

◆ highlightSections

bool QHeaderView::highlightSections
private

whether the sections containing selected items are highlighted

By default, this property is false.

Definition at line 62 of file qheaderview.h.

◆ minimumSectionSize

int QHeaderView::minimumSectionSize
private

the minimum size of the header sections.

Since
4.2

The minimum section size is the smallest section size allowed. If the minimum section size is set to -1, QHeaderView will use the maximum of the global strut or the font metrics size.

This property is honored by all resize modes.

See also
setResizeMode() defaultSectionSize

Definition at line 66 of file qheaderview.h.

◆ showSortIndicator

QHeaderView::showSortIndicator
private

whether the sort indicator is shown

By default, this property is false.

See also
setClickable()

Definition at line 61 of file qheaderview.h.

◆ stretchLastSection

bool QHeaderView::stretchLastSection
private

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

Definition at line 63 of file qheaderview.h.


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