Qt 4.8
Public Slots | Signals | Public Functions | Protected Slots | Protected Functions | Private Functions | Properties | Friends | List of all members
QTreeView Class Reference

The QTreeView class provides a default model/view implementation of a tree view. More...

#include <qtreeview.h>

Inheritance diagram for QTreeView:
QAbstractItemView QAbstractScrollArea QFrame QWidget QObject QPaintDevice QFileDialogTreeView QTreeWidget

Public Slots

void collapse (const QModelIndex &index)
 Collapses the model item specified by the index. More...
 
void collapseAll ()
 Collapses all expanded items. More...
 
void expand (const QModelIndex &index)
 Expands the model item specified by the index. More...
 
void expandAll ()
 Expands all expandable items. More...
 
void expandToDepth (int depth)
 Expands all expandable items to the given depth. More...
 
void hideColumn (int column)
 Hides the column given. More...
 
void resizeColumnToContents (int column)
 Resizes the column given to the size of its contents. More...
 
void showColumn (int column)
 Shows the given column in the tree view. More...
 
void sortByColumn (int column)
 Sorts the model by the values in the given column. 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...
 
void setCurrentIndex (const QModelIndex &index)
 Sets the current item to be the item at 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 collapsed (const QModelIndex &index)
 This signal is emitted when the item specified by index is collapsed. More...
 
void expanded (const QModelIndex &index)
 This signal is emitted when the item specified by index is expanded. More...
 
- 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 allColumnsShowFocus () const
 
int autoExpandDelay () const
 
int columnAt (int x) const
 Returns the column in the tree view whose header covers the x coordinate given. More...
 
int columnViewportPosition (int column) const
 Returns the horizontal position of the column in the viewport. More...
 
int columnWidth (int column) const
 Returns the width of the column. More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 Reimplemented Function More...
 
void doItemsLayout ()
 Lays out the items in the tree view. More...
 
bool expandsOnDoubleClick () const
 
QHeaderViewheader () const
 Returns the header for the tree view. More...
 
int indentation () const
 
QModelIndex indexAbove (const QModelIndex &index) const
 Returns the model index of the item above index. More...
 
QModelIndex indexAt (const QPoint &p) const
 Reimplemented Function More...
 
QModelIndex indexBelow (const QModelIndex &index) const
 Returns the model index of the item below index. More...
 
bool isAnimated () const
 
bool isColumnHidden (int column) const
 Returns true if the column is hidden; otherwise returns false. More...
 
bool isExpanded (const QModelIndex &index) const
 Returns true if the model item index is expanded; otherwise returns false. More...
 
bool isFirstColumnSpanned (int row, const QModelIndex &parent) const
 Returns true if the item in first column in the given row of the parent is spanning all the columns; otherwise returns false. More...
 
bool isHeaderHidden () const
 
bool isRowHidden (int row, const QModelIndex &parent) const
 Returns true if the item in the given row of the parent is hidden; otherwise returns false. More...
 
bool isSortingEnabled () const
 
bool itemsExpandable () const
 
void keyboardSearch (const QString &search)
 Reimplemented Function More...
 
 QTreeView (QWidget *parent=0)
 Constructs a tree view with a parent to represent a model's data. More...
 
void reset ()
 Reimplemented Function More...
 
bool rootIsDecorated () const
 
void scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible)
 Scroll the contents of the tree view until the given model item index is visible. More...
 
void selectAll ()
 Reimplemented Function More...
 
void setAllColumnsShowFocus (bool enable)
 
void setAnimated (bool enable)
 
void setAutoExpandDelay (int delay)
 
void setColumnHidden (int column, bool hide)
 If hide is true the column is hidden, otherwise the column is shown. More...
 
void setColumnWidth (int column, int width)
 Sets the width of the given column to the width specified. More...
 
void setExpanded (const QModelIndex &index, bool expand)
 Sets the item referred to by index to either collapse or expanded, depending on the value of expanded. More...
 
void setExpandsOnDoubleClick (bool enable)
 
void setFirstColumnSpanned (int row, const QModelIndex &parent, bool span)
 If span is true the item in the first column in the row with the given parent is set to span all columns, otherwise all items on the row are shown. More...
 
void setHeader (QHeaderView *header)
 Sets the header for the tree view, to the given header. More...
 
void setHeaderHidden (bool hide)
 
void setIndentation (int i)
 
void setItemsExpandable (bool enable)
 
void setModel (QAbstractItemModel *model)
 Reimplemented Function More...
 
void setRootIndex (const QModelIndex &index)
 Reimplemented Function More...
 
void setRootIsDecorated (bool show)
 
void setRowHidden (int row, const QModelIndex &parent, bool hide)
 If hide is true the row with the given parent is hidden, otherwise the row is shown. More...
 
void setSelectionModel (QItemSelectionModel *selectionModel)
 Reimplemented Function More...
 
void setSortingEnabled (bool enable)
 
void setUniformRowHeights (bool uniform)
 
void setWordWrap (bool on)
 
void sortByColumn (int column, Qt::SortOrder order)
 Sets the model up for sorting by the values in the given column and order. More...
 
bool uniformRowHeights () const
 
QRect visualRect (const QModelIndex &index) const
 Returns the rectangle on the viewport occupied by the item at index. More...
 
bool wordWrap () const
 
 ~QTreeView ()
 Destroys the tree view. 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...
 
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)
 
void setTabKeyNavigation (bool enable)
 
void setTextElideMode (Qt::TextElideMode mode)
 
void setVerticalScrollMode (ScrollMode mode)
 
bool showDropIndicator () const
 
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 columnCountChanged (int oldCount, int newCount)
 Informs the tree view that the number of columns in the tree view has changed from oldCount to newCount. More...
 
void columnMoved ()
 This slot is called whenever a column has been moved. More...
 
void columnResized (int column, int oldSize, int newSize)
 This function is called whenever {column}'s size is changed in the header. More...
 
void reexpand ()
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 Informs the view that the rows from the start row to the end row inclusive have been removed from the given parent model item. 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 horizontalScrollbarValueChanged (int value)
 
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 &previous)
 Reimplemented Function More...
 
void dragMoveEvent (QDragMoveEvent *event)
 Reimplemented Function More...
 
virtual void drawBranches (QPainter *painter, const QRect &rect, const QModelIndex &index) const
 Draws the branches in the tree view on the same row as the model item index, using the painter given. More...
 
virtual void drawRow (QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
 Draws the row in the tree view that contains the model item index, using the painter given. More...
 
void drawTree (QPainter *painter, const QRegion &region) const
 Draws the part of the tree intersecting the given region using the specified painter. More...
 
int horizontalOffset () const
 Returns the horizontal offset of the items in the treeview. More...
 
void horizontalScrollbarAction (int action)
 
int indexRowSizeHint (const QModelIndex &index) const
 Returns the size hint for the row indicated by index. More...
 
bool isIndexHidden (const QModelIndex &index) const
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *event)
 Reimplemented Function More...
 
void mouseDoubleClickEvent (QMouseEvent *event)
 Reimplemented Function More...
 
void mouseMoveEvent (QMouseEvent *event)
 Reimplemented Function More...
 
void mousePressEvent (QMouseEvent *event)
 Reimplemented Function More...
 
void mouseReleaseEvent (QMouseEvent *event)
 Reimplemented Function More...
 
QModelIndex moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
 Move the cursor in the way described by cursorAction, using the information provided by the button modifiers. More...
 
void paintEvent (QPaintEvent *event)
 Reimplemented Function More...
 
 QTreeView (QTreeViewPrivate &dd, QWidget *parent=0)
 
int rowHeight (const QModelIndex &index) const
 Returns the height of the row indicated by the given index. More...
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)
 Informs the view that the rows from the start row to the end row inclusive are about to removed from the given parent model item. More...
 
void rowsInserted (const QModelIndex &parent, int start, int end)
 Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item. More...
 
void scrollContentsBy (int dx, int dy)
 Scrolls the contents of the tree view by (dx, dy). More...
 
QModelIndexList selectedIndexes () const
 Reimplemented Function More...
 
void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 Reimplemented Function More...
 
void setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command)
 Applies the selection command to the items in or touched by the rectangle, rect. More...
 
int sizeHintForColumn (int column) const
 Returns the size hint for the column's width or -1 if there is no model. More...
 
void timerEvent (QTimerEvent *event)
 Reimplemented Function More...
 
void updateGeometries ()
 Reimplemented Function More...
 
int verticalOffset () const
 Returns the vertical offset of the items in the tree view. More...
 
bool viewportEvent (QEvent *event)
 Reimplemented Function More...
 
QRegion visualRegionForSelection (const QItemSelection &selection) const
 Returns the rectangle from the viewport of the items in the given selection. More...
 
- 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 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...
 
bool event (QEvent *event)
 Reimplemented Function 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...
 
 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 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 ()
 
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 ()
 

Private Functions

int visualIndex (const QModelIndex &index) const
 

Properties

bool allColumnsShowFocus
 whether items should show keyboard focus using all columns More...
 
bool animated
 whether animations are enabled More...
 
int autoExpandDelay
 The delay time before items in a tree are opened during a drag and drop operation. More...
 
bool expandsOnDoubleClick
 whether the items can be expanded by double-clicking. More...
 
bool headerHidden
 whether the header is shown or not. More...
 
int indentation
 indentation of the items in the tree view. More...
 
bool itemsExpandable
 whether the items are expandable by the user. More...
 
bool rootIsDecorated
 whether to show controls for expanding and collapsing top-level items More...
 
bool sortingEnabled
 whether sorting is enabled More...
 
bool uniformRowHeights
 whether all items in the treeview have the same height More...
 
bool wordWrap
 the item text word-wrapping policy More...
 

Friends

class QAccessibleItemView
 
class QAccessibleTable2
 
class QAccessibleTable2Cell
 
class QAccessibleTree
 

Additional Inherited Members

- 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
}
 
- 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 QTreeView class provides a default model/view implementation of a tree view.

A QTreeView implements a tree representation of items from a model. This class is used to provide standard hierarchical lists that were previously provided by the QListView class, but using the more flexible approach provided by Qt's model/view architecture.

The QTreeView class is one of the Model/View Classes and is part of Qt's Model/View Programming{model/view framework}.

QTreeView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.

It is simple to construct a tree view displaying data from a model. In the following example, the contents of a directory are supplied by a QFileSystemModel and displayed as a tree:

tree->setModel(model);

The model/view architecture ensures that the contents of the tree view are updated as the model changes.

Items that have children can be in an expanded (children are visible) or collapsed (children are hidden) state. When this state changes a collapsed() or expanded() signal is emitted with the model index of the relevant item.

The amount of indentation used to indicate levels of hierarchy is controlled by the indentation property.

Headers in tree views are constructed using the QHeaderView class and can be hidden using header()->hide(). Note that each header is configured with its QHeaderView::stretchLastSection 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.

Key Bindings

QTreeView supports a set of key bindings that enable the user to navigate in the view and interact with the contents of items:

Key Action
Up Moves the cursor to the item in the same column on the previous row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the last row of the sibling that precedes the parent.
Down Moves the cursor to the item in the same column on the next row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the first row of the sibling that follows the parent.
Left Hides the children of the current item (if present) by collapsing a branch.
Minus Same as LeftArrow.
Right Reveals the children of the current item (if present) by expanding a branch.
Plus Same as RightArrow.
Asterisk Expands all children of the current item (if present).
PageUp Moves the cursor up one page.
PageDown Moves the cursor down one page.
Home Moves the cursor to an item in the same column of the first row of the first top-level item in the model.
End Moves the cursor to an item in the same column of the last row of the last top-level item in the model.
F2 In editable models, this opens the current item for editing. The Escape key can be used to cancel the editing process and revert any changes to the data displayed.
Warning
This function is not part of the public interface. Describe the expanding/collapsing concept if not covered elsewhere.
windowsxp-treeview.png
Screenshot of a Windows XP style tree view
macintosh-treeview.png
Screenshot of a Macintosh style tree view
plastique-treeview.png
Screenshot of a Plastique style tree view
A Windows XP Style Widget Gallery{Windows XP style} tree view. A Macintosh Style Widget Gallery{Macintosh style} tree view. A Plastique Style Widget Gallery{Plastique style} tree view.

Improving Performance

It is possible to give the view hints about the data it is handling in order to improve its performance when displaying large numbers of items. One approach that can be taken for views that are intended to display items with equal heights is to set the uniformRowHeights property to true.

See also
QListView, QTreeWidget, {View Classes}, QAbstractItemModel, QAbstractItemView, {Dir View Example}

Definition at line 58 of file qtreeview.h.

Constructors and Destructors

◆ QTreeView() [1/2]

QTreeView::QTreeView ( QWidget parent = 0)
explicit

Constructs a tree view with a parent to represent a model's data.

Use setModel() to set the model.

See also
QAbstractItemModel

Definition at line 196 of file qtreeview.cpp.

197  : QAbstractItemView(*new QTreeViewPrivate, parent)
198 {
199  Q_D(QTreeView);
200  d->initialize();
201 }
double d
Definition: qnumeric_p.h:62
QAbstractItemView(QWidget *parent=0)
Constructs an abstract item view with the given parent.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ ~QTreeView()

QTreeView::~QTreeView ( )

Destroys the tree view.

Definition at line 216 of file qtreeview.cpp.

217 {
218 }

◆ QTreeView() [2/2]

QTreeView::QTreeView ( QTreeViewPrivate dd,
QWidget parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 206 of file qtreeview.cpp.

207  : QAbstractItemView(dd, parent)
208 {
209  Q_D(QTreeView);
210  d->initialize();
211 }
double d
Definition: qnumeric_p.h:62
QAbstractItemView(QWidget *parent=0)
Constructs an abstract item view with the given parent.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

Functions

◆ allColumnsShowFocus()

bool QTreeView::allColumnsShowFocus ( ) const

◆ autoExpandDelay()

int QTreeView::autoExpandDelay ( ) const

Referenced by setHeader().

◆ collapse

void QTreeView::collapse ( const QModelIndex index)
slot

Collapses the model item specified by the index.

See also
collapsed()

Definition at line 821 of file qtreeview.cpp.

Referenced by QTreeWidget::collapseItem(), QTreeViewPrivate::expandOrCollapseItemAtPos(), keyPressEvent(), and setExpanded().

822 {
823  Q_D(QTreeView);
824  if (!d->isIndexValid(index))
825  return;
826  //if the current item is now invisible, the autoscroll will expand the tree to see it, so disable the autoscroll
827  d->delayedAutoScroll.stop();
828 
829  if (d->delayedPendingLayout) {
830  //A complete relayout is going to be performed, just un-store the expanded index, no need to layout.
831  if (d->isPersistent(index) && d->expandedIndexes.remove(index))
832  emit collapsed(index);
833  return;
834  }
835  int i = d->viewIndex(index);
836  if (i != -1) { // is visible
837  d->collapse(i, true);
838  if (!d->isAnimating()) {
840  viewport()->update();
841  }
842  } else {
843  if (d->isPersistent(index) && d->expandedIndexes.remove(index))
844  emit collapsed(index);
845  }
846 }
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
#define emit
Definition: qobjectdefs.h:76
void collapsed(const QModelIndex &index)
This signal is emitted when the item specified by index is collapsed.

◆ collapseAll

void QTreeView::collapseAll ( )
slot

Collapses all expanded items.

Since
4.2
See also
expandAll() expand() collapse() setExpanded()

Definition at line 2715 of file qtreeview.cpp.

2716 {
2717  Q_D(QTreeView);
2718  d->expandedIndexes.clear();
2719  doItemsLayout();
2720 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void doItemsLayout()
Lays out the items in the tree view.
Definition: qtreeview.cpp:2080

◆ collapsed

void QTreeView::collapsed ( const QModelIndex index)
signal

This signal is emitted when the item specified by index is collapsed.

Referenced by collapse(), and QTreeWidget::QTreeWidget().

◆ columnAt()

int QTreeView::columnAt ( int  x) const

Returns the column in the tree view whose header covers the x coordinate given.

Definition at line 548 of file qtreeview.cpp.

549 {
550  Q_D(const QTreeView);
551  return d->header->logicalIndexAt(x);
552 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int x() const

◆ columnCountChanged

void QTreeView::columnCountChanged ( int  oldCount,
int  newCount 
)
protectedslot

Informs the tree view that the number of columns in the tree view has changed from oldCount to newCount.

Definition at line 2595 of file qtreeview.cpp.

Referenced by setHeader().

2596 {
2597  Q_D(QTreeView);
2598  if (oldCount == 0 && newCount > 0) {
2599  //if the first column has just been added we need to relayout.
2600  d->doDelayedItemsLayout();
2601  }
2602 
2603  if (isVisible())
2604  updateGeometries();
2605  viewport()->update();
2606 }
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
bool isVisible() const
Definition: qwidget.h:1005
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ columnMoved

void QTreeView::columnMoved ( )
protectedslot

This slot is called whenever a column has been moved.

Definition at line 2509 of file qtreeview.cpp.

Referenced by setHeader().

2510 {
2511  Q_D(QTreeView);
2513  d->viewport->update();
2514 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
virtual void updateEditorGeometries()
Updates the geometry of the open editor widgets in the view.

◆ columnResized

void QTreeView::columnResized ( int  column,
int  oldSize,
int  newSize 
)
protectedslot

This function is called whenever {column}'s size is changed in the header.

oldSize and newSize give the previous size and the new size in pixels.

See also
setColumnWidth()

Definition at line 2756 of file qtreeview.cpp.

Referenced by setHeader().

2757 {
2758  Q_D(QTreeView);
2759  d->columnsToUpdate.append(column);
2760  if (d->columnResizeTimerID == 0)
2761  d->columnResizeTimerID = startTimer(0);
2762 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ columnViewportPosition()

int QTreeView::columnViewportPosition ( int  column) const

Returns the horizontal position of the column in the viewport.

Definition at line 511 of file qtreeview.cpp.

Referenced by drawRow(), scrollTo(), timerEvent(), visualRect(), and visualRegionForSelection().

512 {
513  Q_D(const QTreeView);
514  return d->header->sectionViewportPosition(column);
515 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ columnWidth()

int QTreeView::columnWidth ( int  column) const

Returns the width of the column.

See also
resizeColumnToContents(), setColumnWidth()

Definition at line 522 of file qtreeview.cpp.

Referenced by scrollTo(), timerEvent(), visualRect(), and visualRegionForSelection().

523 {
524  Q_D(const QTreeView);
525  return d->header->sectionSize(column);
526 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ currentChanged()

void QTreeView::currentChanged ( const QModelIndex current,
const QModelIndex previous 
)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 3821 of file qtreeview.cpp.

Referenced by QTreeWidget::QTreeWidget().

3822 {
3823  QAbstractItemView::currentChanged(current, previous);
3824 
3825  if (allColumnsShowFocus()) {
3826  if (previous.isValid()) {
3827  QRect previousRect = visualRect(previous);
3828  previousRect.setX(0);
3829  previousRect.setWidth(viewport()->width());
3830  viewport()->update(previousRect);
3831  }
3832  if (current.isValid()) {
3833  QRect currentRect = visualRect(current);
3834  currentRect.setX(0);
3835  currentRect.setWidth(viewport()->width());
3836  viewport()->update(currentRect);
3837  }
3838  }
3839 #ifndef QT_NO_ACCESSIBILITY
3840  if (QAccessible::isActive() && current.isValid()) {
3841 #ifdef Q_WS_X11
3842  int entry = (visualIndex(current) + (header()?1:0))*current.model()->columnCount()+current.column() + 1;
3844 #else
3845  int entry = visualIndex(current) + 1;
3846  if (header())
3847  ++entry;
3849 #endif
3850  }
3851 #endif
3852 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
int width() const
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
int visualIndex(const QModelIndex &index) const
Definition: qtreeview.cpp:3894
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:282
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
QRect visualRect(const QModelIndex &index) const
Returns the rectangle on the viewport occupied by the item at index.
Definition: qtreeview.cpp:1101
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool allColumnsShowFocus() const
int column() const
Returns the column this model index refers to.

◆ dataChanged()

void QTreeView::dataChanged ( const QModelIndex topLeft,
const QModelIndex bottomRight 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 706 of file qtreeview.cpp.

Referenced by QTreeWidget::QTreeWidget().

707 {
708  Q_D(QTreeView);
709 
710  // if we are going to do a complete relayout anyway, there is no need to update
711  if (d->delayedPendingLayout)
712  return;
713 
714  // refresh the height cache here; we don't really lose anything by getting the size hint,
715  // since QAbstractItemView::dataChanged() will get the visualRect for the items anyway
716 
717  bool sizeChanged = false;
718  int topViewIndex = d->viewIndex(topLeft);
719  if (topViewIndex == 0) {
720  int newDefaultItemHeight = indexRowSizeHint(topLeft);
721  sizeChanged = d->defaultItemHeight != newDefaultItemHeight;
722  d->defaultItemHeight = newDefaultItemHeight;
723  }
724 
725  if (topViewIndex != -1) {
726  if (topLeft.row() == bottomRight.row()) {
727  int oldHeight = d->itemHeight(topViewIndex);
728  d->invalidateHeightCache(topViewIndex);
729  sizeChanged |= (oldHeight != d->itemHeight(topViewIndex));
730  if (topLeft.column() == 0)
731  d->viewItems[topViewIndex].hasChildren = d->hasVisibleChildren(topLeft);
732  } else {
733  int bottomViewIndex = d->viewIndex(bottomRight);
734  for (int i = topViewIndex; i <= bottomViewIndex; ++i) {
735  int oldHeight = d->itemHeight(i);
736  d->invalidateHeightCache(i);
737  sizeChanged |= (oldHeight != d->itemHeight(i));
738  if (topLeft.column() == 0)
739  d->viewItems[i].hasChildren = d->hasVisibleChildren(d->viewItems.at(i).index);
740  }
741  }
742  }
743 
744  if (sizeChanged) {
745  d->updateScrollBars();
746  d->viewport->update();
747  }
748  QAbstractItemView::dataChanged(topLeft, bottomRight);
749 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This slot is called when items are changed in the model.
int indexRowSizeHint(const QModelIndex &index) const
Returns the size hint for the row indicated by index.
Definition: qtreeview.cpp:2843
int column() const
Returns the column this model index refers to.

◆ doItemsLayout()

void QTreeView::doItemsLayout ( )
virtual

Lays out the items in the tree view.

Warning
This function is not part of the public interface.

Reimplemented from QAbstractItemView.

Definition at line 2080 of file qtreeview.cpp.

Referenced by collapseAll().

2081 {
2082  Q_D(QTreeView);
2083  if (d->hasRemovedItems) {
2084  //clean the QSet that may contains old (and this invalid) indexes
2085  d->hasRemovedItems = false;
2086  QSet<QPersistentModelIndex>::iterator it = d->expandedIndexes.begin();
2087  while (it != d->expandedIndexes.constEnd()) {
2088  if (!it->isValid())
2089  it = d->expandedIndexes.erase(it);
2090  else
2091  ++it;
2092  }
2093  it = d->hiddenIndexes.begin();
2094  while (it != d->hiddenIndexes.constEnd()) {
2095  if (!it->isValid())
2096  it = d->hiddenIndexes.erase(it);
2097  else
2098  ++it;
2099  }
2100  }
2101  d->viewItems.clear(); // prepare for new layout
2102  QModelIndex parent = d->root;
2103  if (d->model->hasChildren(parent)) {
2104  d->layout(-1);
2105  }
2107  d->header->doItemsLayout();
2108 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.

◆ dragMoveEvent()

void QTreeView::dragMoveEvent ( QDragMoveEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1277 of file qtreeview.cpp.

1278 {
1279  Q_D(QTreeView);
1280  if (d->autoExpandDelay >= 0)
1281  d->openTimer.start(d->autoExpandDelay, this);
1283 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void dragMoveEvent(QDragMoveEvent *event)
This function is called continuously with the given event during a drag and drop operation over the w...
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ drawBranches()

void QTreeView::drawBranches ( QPainter painter,
const QRect rect,
const QModelIndex index 
) const
protectedvirtual

Draws the branches in the tree view on the same row as the model item index, using the painter given.

The branches are drawn in the rectangle specified by rect.

Definition at line 1788 of file qtreeview.cpp.

Referenced by drawRow().

1790 {
1791  Q_D(const QTreeView);
1792  const bool reverse = isRightToLeft();
1793  const int indent = d->indent;
1794  const int outer = d->rootDecoration ? 0 : 1;
1795  const int item = d->current;
1796  const QTreeViewItem &viewItem = d->viewItems.at(item);
1797  int level = viewItem.level;
1798  QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height());
1799 
1800  QModelIndex parent = index.parent();
1801  QModelIndex current = parent;
1802  QModelIndex ancestor = current.parent();
1803 
1805  QStyle::State extraFlags = QStyle::State_None;
1806  if (isEnabled())
1807  extraFlags |= QStyle::State_Enabled;
1808  if (window()->isActiveWindow())
1809  extraFlags |= QStyle::State_Active;
1810  QPoint oldBO = painter->brushOrigin();
1812  painter->setBrushOrigin(QPoint(0, verticalOffset()));
1813 
1814  if (d->alternatingColors) {
1815  if (d->current & 1) {
1817  } else {
1818  opt.features &= ~QStyleOptionViewItemV2::Alternate;
1819  }
1820  }
1821 
1822  // When hovering over a row, pass State_Hover for painting the branch
1823  // indicators if it has the decoration (aka branch) selected.
1825  && opt.showDecorationSelected
1826  && index.parent() == d->hover.parent()
1827  && index.row() == d->hover.row();
1828 
1829  if (d->selectionModel->isSelected(index))
1830  extraFlags |= QStyle::State_Selected;
1831 
1832  if (level >= outer) {
1833  // start with the innermost branch
1834  primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1835  opt.rect = primitive;
1836 
1837  const bool expanded = viewItem.expanded;
1838  const bool children = viewItem.hasChildren;
1839  bool moreSiblings = viewItem.hasMoreSiblings;
1840 
1841  opt.state = QStyle::State_Item | extraFlags
1842  | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None)
1844  | (expanded ? QStyle::State_Open : QStyle::State_None);
1845  if (hoverRow || item == d->hoverBranch)
1847  else
1848  opt.state &= ~QStyle::State_MouseOver;
1849  style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this);
1850  }
1851  // then go out level by level
1852  for (--level; level >= outer; --level) { // we have already drawn the innermost branch
1853  primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1854  opt.rect = primitive;
1855  opt.state = extraFlags;
1856  bool moreSiblings = false;
1857  if (d->hiddenIndexes.isEmpty()) {
1858  moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row());
1859  } else {
1860  int successor = item + viewItem.total + 1;
1861  while (successor < d->viewItems.size()
1862  && d->viewItems.at(successor).level >= uint(level)) {
1863  const QTreeViewItem &successorItem = d->viewItems.at(successor);
1864  if (successorItem.level == uint(level)) {
1865  moreSiblings = true;
1866  break;
1867  }
1868  successor += successorItem.total + 1;
1869  }
1870  }
1871  if (moreSiblings)
1873  if (hoverRow || item == d->hoverBranch)
1875  else
1876  opt.state &= ~QStyle::State_MouseOver;
1877  style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this);
1878  current = ancestor;
1879  ancestor = current.parent();
1880  }
1881  painter->setBrushOrigin(oldBO);
1882 }
double d
Definition: qnumeric_p.h:62
virtual QStyleOptionViewItem viewOptions() const
Returns a QStyleOptionViewItem structure populated with the view&#39;s palette, font, state...
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
static C reverse(const C &l)
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
bool isActiveWindow() const
#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
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
QStyle * style() const
Definition: qwidget.cpp:2742
The QStyleOptionViewItemV2 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:562
void expanded(const QModelIndex &index)
This signal is emitted when the item specified by index is expanded.
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
QPoint brushOrigin() const
Returns the currently set brush origin.
Definition: qpainter.cpp:2168
ScrollMode verticalScrollMode() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
unsigned int uint
Definition: qglobal.h:996
int verticalOffset() const
Returns the vertical offset of the items in the tree view.
Definition: qtreeview.cpp:2142
QAbstractItemView::SelectionBehavior selectionBehavior() const
uint hasMoreSiblings
Definition: qtreeview_p.h:73
bool isEnabled() const
Definition: qwidget.h:948
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
State
Definition: qaudio.h:59
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QModelIndex class is used to locate data in a data model.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
uint hasChildren
Definition: qtreeview_p.h:72
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
bool isRightToLeft() const
Definition: qwidget.h:428
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90

◆ drawRow()

void QTreeView::drawRow ( QPainter painter,
const QStyleOptionViewItem option,
const QModelIndex index 
) const
protectedvirtual

Draws the row in the tree view that contains the model item index, using the painter given.

The option control how the item is displayed.

See also
setAlternatingRowColors()

Definition at line 1590 of file qtreeview.cpp.

Referenced by drawTree().

1592 {
1593  Q_D(const QTreeView);
1594  QStyleOptionViewItemV4 opt = option;
1595  const QPoint offset = d->scrollDelayOffset;
1596  const int y = option.rect.y() + offset.y();
1597  const QModelIndex parent = index.parent();
1598  const QHeaderView *header = d->header;
1599  const QModelIndex current = currentIndex();
1600  const QModelIndex hover = d->hover;
1601  const bool reverse = isRightToLeft();
1602  const QStyle::State state = opt.state;
1603  const bool spanning = d->spanning;
1604  const int left = (spanning ? header->visualIndex(0) : d->leftAndRight.first);
1605  const int right = (spanning ? header->visualIndex(0) : d->leftAndRight.second);
1606  const bool alternate = d->alternatingColors;
1607  const bool enabled = (state & QStyle::State_Enabled) != 0;
1608  const bool allColumnsShowFocus = d->allColumnsShowFocus;
1609 
1610 
1611  // when the row contains an index widget which has focus,
1612  // we want to paint the entire row as active
1613  bool indexWidgetHasFocus = false;
1614  if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) {
1615  const int r = index.row();
1617  for (int c = 0; c < header->count(); ++c) {
1618  QModelIndex idx = d->model->index(r, c, parent);
1619  if (QWidget *editor = indexWidget(idx)) {
1620  if (ancestorOf(editor, fw)) {
1621  indexWidgetHasFocus = true;
1622  break;
1623  }
1624  }
1625  }
1626  }
1627 
1628  const bool widgetHasFocus = hasFocus();
1629  bool currentRowHasFocus = false;
1630  if (allColumnsShowFocus && widgetHasFocus && current.isValid()) {
1631  // check if the focus index is before or after the visible columns
1632  const int r = index.row();
1633  for (int c = 0; c < left && !currentRowHasFocus; ++c) {
1634  QModelIndex idx = d->model->index(r, c, parent);
1635  currentRowHasFocus = (idx == current);
1636  }
1637  QModelIndex parent = d->model->parent(index);
1638  for (int c = right; c < header->count() && !currentRowHasFocus; ++c) {
1639  currentRowHasFocus = (d->model->index(r, c, parent) == current);
1640  }
1641  }
1642 
1643  // ### special case: treeviews with multiple columns draw
1644  // the selections differently than with only one column
1645  opt.showDecorationSelected = (d->selectionBehavior & SelectRows)
1646  || option.showDecorationSelected;
1647 
1648  int width, height = option.rect.height();
1649  int position;
1650  QModelIndex modelIndex;
1651  const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1652  && index.parent() == hover.parent()
1653  && index.row() == hover.row();
1654 
1655  QVector<int> logicalIndices;
1656  QVector<QStyleOptionViewItemV4::ViewItemPosition> viewItemPosList; // vector of left/middle/end for each logicalIndex
1657  d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1658 
1659  for (int currentLogicalSection = 0; currentLogicalSection < logicalIndices.count(); ++currentLogicalSection) {
1660  int headerSection = logicalIndices.at(currentLogicalSection);
1661  position = columnViewportPosition(headerSection) + offset.x();
1662  width = header->sectionSize(headerSection);
1663 
1664  if (spanning) {
1665  int lastSection = header->logicalIndex(header->count() - 1);
1666  if (!reverse) {
1667  width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position;
1668  } else {
1669  width += position - columnViewportPosition(lastSection);
1670  position = columnViewportPosition(lastSection);
1671  }
1672  }
1673 
1674  modelIndex = d->model->index(index.row(), headerSection, parent);
1675  if (!modelIndex.isValid())
1676  continue;
1677  opt.state = state;
1678 
1679  opt.viewItemPosition = viewItemPosList.at(currentLogicalSection);
1680 
1681  // fake activeness when row editor has focus
1682  if (indexWidgetHasFocus)
1683  opt.state |= QStyle::State_Active;
1684 
1685  if (d->selectionModel->isSelected(modelIndex))
1687  if (widgetHasFocus && (current == modelIndex)) {
1688  if (allColumnsShowFocus)
1689  currentRowHasFocus = true;
1690  else
1692  }
1693  if ((hoverRow || modelIndex == hover)
1694  && (option.showDecorationSelected || (d->hoverBranch == -1)))
1696  else
1698 
1699  if (enabled) {
1701  if ((d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0) {
1702  opt.state &= ~QStyle::State_Enabled;
1703  cg = QPalette::Disabled;
1704  } else if (opt.state & QStyle::State_Active) {
1705  cg = QPalette::Active;
1706  } else {
1707  cg = QPalette::Inactive;
1708  }
1709  opt.palette.setCurrentColorGroup(cg);
1710  }
1711 
1712  if (alternate) {
1713  if (d->current & 1) {
1715  } else {
1716  opt.features &= ~QStyleOptionViewItemV2::Alternate;
1717  }
1718  }
1719 
1720  /* Prior to Qt 4.3, the background of the branch (in selected state and
1721  alternate row color was provided by the view. For backward compatibility,
1722  this is now delegated to the style using PE_PanelViewItemRow which
1723  does the appropriate fill */
1724  if (headerSection == 0) {
1725  const int i = d->indentationForItem(d->current);
1726  QRect branches(reverse ? position + width - i : position, y, i, height);
1727  const bool setClipRect = branches.width() > width;
1728  if (setClipRect) {
1729  painter->save();
1730  painter->setClipRect(QRect(position, y, width, height));
1731  }
1732  // draw background for the branch (selection + alternate row)
1733  opt.rect = branches;
1734  style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
1735 
1736  // draw background of the item (only alternate row). rest of the background
1737  // is provided by the delegate
1738  QStyle::State oldState = opt.state;
1739  opt.state &= ~QStyle::State_Selected;
1740  opt.rect.setRect(reverse ? position : i + position, y, width - i, height);
1741  style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
1742  opt.state = oldState;
1743 
1744  drawBranches(painter, branches, index);
1745  if (setClipRect)
1746  painter->restore();
1747  } else {
1748  QStyle::State oldState = opt.state;
1749  opt.state &= ~QStyle::State_Selected;
1750  opt.rect.setRect(position, y, width, height);
1751  style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
1752  opt.state = oldState;
1753  }
1754 
1755  d->delegateForIndex(modelIndex)->paint(painter, opt, modelIndex);
1756  }
1757 
1758  if (currentRowHasFocus) {
1760  o.QStyleOption::operator=(option);
1764  o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index)
1766  int x = 0;
1767  if (!option.showDecorationSelected)
1768  x = header->sectionPosition(0) + d->indentationForItem(d->current);
1769  QRect focusRect(x - header->offset(), y, header->length() - x, height);
1770  o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect);
1772  // if we show focus on all columns and the first section is moved,
1773  // we have to split the focus rect into two rects
1774  if (allColumnsShowFocus && !option.showDecorationSelected
1775  && header->sectionsMoved() && (header->visualIndex(0) != 0)) {
1776  QRect sectionRect(0, y, header->sectionPosition(0), height);
1777  o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect);
1779  }
1780  }
1781 }
double d
Definition: qnumeric_p.h:62
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
static bool ancestorOf(QObject *widget, QObject *other)
move to QObject :)
Definition: qtreeview.cpp:1523
int y() const
unsigned char c[8]
Definition: qnumeric_p.h:62
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
static C reverse(const C &l)
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
int columnViewportPosition(int column) const
Returns the horizontal position of the column in the viewport.
Definition: qtreeview.cpp:511
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
int height() const
bool sectionsMoved() const
Returns true if sections in the header has been moved; otherwise returns false;.
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QWidget * indexWidget(const QModelIndex &index) const
Returns the widget for the item at the given index.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
QStyle * style() const
Definition: qwidget.cpp:2742
The QStyleOptionViewItemV2 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:562
ColorGroup
Definition: qpalette.h:92
QColor backgroundColor
the background color on which the focus rectangle is being drawn
Definition: qstyleoption.h:109
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
int offset() const
Returns the offset of the header: this is the header&#39;s left-most (or top-most for vertical headers) v...
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
int width() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QStyleOptionFocusRect class is used to describe the parameters for drawing a focus rectangle with...
Definition: qstyleoption.h:103
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
QModelIndex currentIndex() const
Returns the model index of the current item.
int length() const
Returns the length along the orientation of the header.
QAbstractItemView::SelectionBehavior selectionBehavior() const
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
ViewItemPosition viewItemPosition
Gives the position of this view item relative to other items.
Definition: qstyleoption.h:619
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
int x() const
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
Qt::LayoutDirection layoutDirection() const
State
Definition: qaudio.h:59
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
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
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
The QModelIndex class is used to locate data in a data model.
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.
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
State state() const
Returns the item view&#39;s state.
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
int sectionPosition(int logicalIndex) const
Returns the section position of the given logicalIndex, or -1 if the section is hidden.
bool allColumnsShowFocus() const
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
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
virtual void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
Draws the branches in the tree view on the same row as the model item index, using the painter given...
Definition: qtreeview.cpp:1788

◆ drawTree()

void QTreeView::drawTree ( QPainter painter,
const QRegion region 
) const
protected

Draws the part of the tree intersecting the given region using the specified painter.

Since
4.2
See also
paintEvent()

Definition at line 1452 of file qtreeview.cpp.

Referenced by paintEvent().

1453 {
1454  Q_D(const QTreeView);
1455  const QVector<QTreeViewItem> viewItems = d->viewItems;
1456 
1457  QStyleOptionViewItemV4 option = d->viewOptionsV4();
1458  const QStyle::State state = option.state;
1459  d->current = 0;
1460 
1461  if (viewItems.count() == 0 || d->header->count() == 0 || !d->itemDelegate) {
1462  d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1463  return;
1464  }
1465 
1466  int firstVisibleItemOffset = 0;
1467  const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset);
1468  if (firstVisibleItem < 0) {
1469  d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1470  return;
1471  }
1472 
1473  const int viewportWidth = d->viewport->width();
1474 
1475  QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
1476  d->hoverBranch = d->itemDecorationAt(hoverPos);
1477 
1478  QVector<QRect> rects = region.rects();
1479  QVector<int> drawn;
1480  bool multipleRects = (rects.size() > 1);
1481  for (int a = 0; a < rects.size(); ++a) {
1482  const QRect area = (multipleRects
1483  ? QRect(0, rects.at(a).y(), viewportWidth, rects.at(a).height())
1484  : rects.at(a));
1485  d->leftAndRight = d->startAndEndColumns(area);
1486 
1487  int i = firstVisibleItem; // the first item at the top of the viewport
1488  int y = firstVisibleItemOffset; // we may only see part of the first item
1489 
1490  // start at the top of the viewport and iterate down to the update area
1491  for (; i < viewItems.count(); ++i) {
1492  const int itemHeight = d->itemHeight(i);
1493  if (y + itemHeight > area.top())
1494  break;
1495  y += itemHeight;
1496  }
1497 
1498  // paint the visible rows
1499  for (; i < viewItems.count() && y <= area.bottom(); ++i) {
1500  const int itemHeight = d->itemHeight(i);
1501  option.rect.setRect(0, y, viewportWidth, itemHeight);
1502  option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None)
1505  d->current = i;
1506  d->spanning = viewItems.at(i).spanning;
1507  if (!multipleRects || !drawn.contains(i)) {
1508  drawRow(painter, option, viewItems.at(i).index);
1509  if (multipleRects) // even if the rect only intersects the item,
1510  drawn.append(i); // the entire item will be painted
1511  }
1512  y += itemHeight;
1513  }
1514 
1515  if (y <= area.bottom()) {
1516  d->current = i;
1517  d->paintAlternatingRowColors(painter, &option, y, area.bottom());
1518  }
1519  }
1520 }
double d
Definition: qnumeric_p.h:62
int y() const
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
long ASN1_INTEGER_get ASN1_INTEGER * a
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
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
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
uint hasMoreSiblings
Definition: qtreeview_p.h:73
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
State
Definition: qaudio.h:59
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
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
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
uint hasChildren
Definition: qtreeview_p.h:72
QModelIndex index
Definition: qtreeview_p.h:68
State state() const
Returns the item view&#39;s state.
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
virtual void drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
Draws the row in the tree view that contains the model item index, using the painter given...
Definition: qtreeview.cpp:1590
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ expand

void QTreeView::expand ( const QModelIndex index)
slot

Expands the model item specified by the index.

See also
expanded()

Definition at line 787 of file qtreeview.cpp.

Referenced by QTreeWidget::expandItem(), QTreeViewPrivate::expandOrCollapseItemAtPos(), keyPressEvent(), scrollTo(), setExpanded(), and QTreeWidget::setItemExpanded().

788 {
789  Q_D(QTreeView);
790  if (!d->isIndexValid(index))
791  return;
792  if (d->delayedPendingLayout) {
793  //A complete relayout is going to be performed, just store the expanded index, no need to layout.
794  if (d->storeExpanded(index))
795  emit expanded(index);
796  return;
797  }
798 
799  int i = d->viewIndex(index);
800  if (i != -1) { // is visible
801  d->expand(i, true);
802  if (!d->isAnimating()) {
804  d->viewport->update();
805  }
806  } else if (d->storeExpanded(index)) {
807  emit expanded(index);
808  }
809 }
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
#define Q_D(Class)
Definition: qglobal.h:2482
void expanded(const QModelIndex &index)
This signal is emitted when the item specified by index is expanded.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
#define emit
Definition: qobjectdefs.h:76

◆ expandAll

void QTreeView::expandAll ( )
slot

Expands all expandable items.

Since
4.2

Warning: if the model contains a large number of items, this function will take some time to execute.

See also
collapseAll() expand() collapse() setExpanded()

Definition at line 2695 of file qtreeview.cpp.

2696 {
2697  Q_D(QTreeView);
2698  d->viewItems.clear();
2699  d->interruptDelayedItemsLayout();
2700  d->layout(-1, true);
2701  updateGeometries();
2702  d->viewport->update();
2703 }
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ expanded

void QTreeView::expanded ( const QModelIndex index)
signal

This signal is emitted when the item specified by index is expanded.

Referenced by drawBranches(), expand(), QTreeWidget::QTreeWidget(), and QFSCompleter::splitPath().

◆ expandsOnDoubleClick()

bool QTreeView::expandsOnDoubleClick ( ) const

Referenced by setItemsExpandable().

◆ expandToDepth

void QTreeView::expandToDepth ( int  depth)
slot

Expands all expandable items to the given depth.

Since
4.3
See also
expandAll() collapseAll() expand() collapse() setExpanded()

Definition at line 2731 of file qtreeview.cpp.

2732 {
2733  Q_D(QTreeView);
2734  d->viewItems.clear();
2735  d->expandedIndexes.clear();
2736  d->interruptDelayedItemsLayout();
2737  d->layout(-1);
2738  for (int i = 0; i < d->viewItems.count(); ++i) {
2739  if (d->viewItems.at(i).level <= (uint)depth) {
2740  d->viewItems[i].expanded = true;
2741  d->layout(i);
2742  d->storeExpanded(d->viewItems.at(i).index);
2743  }
2744  }
2745  updateGeometries();
2746  d->viewport->update();
2747 }
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
unsigned int uint
Definition: qglobal.h:996
int depth() const
Definition: qpaintdevice.h:103

◆ header()

QHeaderView * QTreeView::header ( ) const

◆ hideColumn

void QTreeView::hideColumn ( int  column)
slot

Hides the column given.

Note
This function should only be called after the model has been initialized, as the view needs to know the number of columns in order to hide column.
See also
showColumn(), setColumnHidden()

Definition at line 760 of file qtreeview.cpp.

761 {
762  Q_D(QTreeView);
763  d->header->hideSection(column);
764 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ horizontalOffset()

int QTreeView::horizontalOffset ( ) const
protectedvirtual

Returns the horizontal offset of the items in the treeview.

Note that the tree view uses the horizontal header section positions to determine the positions of columns in the view.

See also
verticalOffset()

Implements QAbstractItemView.

Definition at line 2131 of file qtreeview.cpp.

Referenced by scrollTo().

2132 {
2133  Q_D(const QTreeView);
2134  return d->header->offset();
2135 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ horizontalScrollbarAction()

void QTreeView::horizontalScrollbarAction ( int  action)
protectedvirtual
Warning
This function is not part of the public interface.

Reimplemented from QAbstractItemView.

Definition at line 2926 of file qtreeview.cpp.

2927 {
2929 }
virtual void horizontalScrollbarAction(int action)

◆ indentation()

int QTreeView::indentation ( ) const

Referenced by setAutoExpandDelay().

◆ indexAbove()

QModelIndex QTreeView::indexAbove ( const QModelIndex index) const

Returns the model index of the item above index.

Definition at line 2045 of file qtreeview.cpp.

Referenced by QTreeWidget::itemAbove().

2046 {
2047  Q_D(const QTreeView);
2048  if (!d->isIndexValid(index))
2049  return QModelIndex();
2050  d->executePostedLayout();
2051  int i = d->viewIndex(index);
2052  if (--i < 0)
2053  return QModelIndex();
2054  return d->viewItems.at(i).index;
2055 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
The QModelIndex class is used to locate data in a data model.

◆ indexAt()

QModelIndex QTreeView::indexAt ( const QPoint p) const
virtual

Reimplemented Function

Implements QAbstractItemView.

Definition at line 2021 of file qtreeview.cpp.

Referenced by QTreeWidget::itemAt(), mouseDoubleClickEvent(), setSelection(), timerEvent(), and viewportEvent().

2022 {
2023  Q_D(const QTreeView);
2024  d->executePostedLayout();
2025 
2026  int visualIndex = d->itemAtCoordinate(point.y());
2027  QModelIndex idx = d->modelIndex(visualIndex);
2028  if (!idx.isValid())
2029  return QModelIndex();
2030 
2031  if (d->viewItems.at(visualIndex).spanning)
2032  return idx;
2033 
2034  int column = d->columnAt(point.x());
2035  if (column == idx.column())
2036  return idx;
2037  if (column < 0)
2038  return QModelIndex();
2039  return idx.sibling(idx.row(), column);
2040 }
double d
Definition: qnumeric_p.h:62
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
int visualIndex(const QModelIndex &index) const
Definition: qtreeview.cpp:3894
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
int column() const
Returns the column this model index refers to.

◆ indexBelow()

QModelIndex QTreeView::indexBelow ( const QModelIndex index) const

Returns the model index of the item below index.

Definition at line 2060 of file qtreeview.cpp.

Referenced by QTreeWidget::itemBelow(), and keyboardSearch().

2061 {
2062  Q_D(const QTreeView);
2063  if (!d->isIndexValid(index))
2064  return QModelIndex();
2065  d->executePostedLayout();
2066  int i = d->viewIndex(index);
2067  if (++i >= d->viewItems.count())
2068  return QModelIndex();
2069  return d->viewItems.at(i).index;
2070 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
The QModelIndex class is used to locate data in a data model.

◆ indexRowSizeHint()

int QTreeView::indexRowSizeHint ( const QModelIndex index) const
protected

Returns the size hint for the row indicated by index.

See also
sizeHintForColumn(), uniformRowHeights()

Definition at line 2843 of file qtreeview.cpp.

Referenced by dataChanged().

2844 {
2845  Q_D(const QTreeView);
2846  if (!d->isIndexValid(index) || !d->itemDelegate)
2847  return 0;
2848 
2849  int start = -1;
2850  int end = -1;
2851  int indexRow = index.row();
2852  int count = d->header->count();
2853  bool emptyHeader = (count == 0);
2854  QModelIndex parent = index.parent();
2855 
2856  if (count && isVisible()) {
2857  // If the sections have moved, we end up checking too many or too few
2858  start = d->header->visualIndexAt(0);
2859  } else {
2860  // If the header has not been laid out yet, we use the model directly
2861  count = d->model->columnCount(parent);
2862  }
2863 
2864  if (isRightToLeft()) {
2865  start = (start == -1 ? count - 1 : start);
2866  end = 0;
2867  } else {
2868  start = (start == -1 ? 0 : start);
2869  end = count - 1;
2870  }
2871 
2872  if (end < start)
2873  qSwap(end, start);
2874 
2875  int height = -1;
2876  QStyleOptionViewItemV4 option = d->viewOptionsV4();
2877  // ### If we want word wrapping in the items,
2878  // ### we need to go through all the columns
2879  // ### and set the width of the column
2880 
2881  // Hack to speed up the function
2882  option.rect.setWidth(-1);
2883 
2884  for (int column = start; column <= end; ++column) {
2885  int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column);
2886  if (d->header->isSectionHidden(logicalColumn))
2887  continue;
2888  QModelIndex idx = d->model->index(indexRow, logicalColumn, parent);
2889  if (idx.isValid()) {
2890  QWidget *editor = d->editorForIndex(idx).widget.data();
2891  if (editor && d->persistent.contains(editor)) {
2892  height = qMax(height, editor->sizeHint().height());
2893  int min = editor->minimumSize().height();
2894  int max = editor->maximumSize().height();
2895  height = qBound(min, height, max);
2896  }
2897  int hint = d->delegateForIndex(idx)->sizeHint(option, idx).height();
2898  height = qMax(height, hint);
2899  }
2900  }
2901 
2902  return height;
2903 }
double d
Definition: qnumeric_p.h:62
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
QSize minimumSize
the widget&#39;s minimum size
Definition: qwidget.h:172
bool isVisible() const
Definition: qwidget.h:1005
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
The QModelIndex class is used to locate data in a data model.
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
int height() const
Returns the height.
Definition: qsize.h:129
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
bool isRightToLeft() const
Definition: qwidget.h:428
static const KeyPair *const end
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90

◆ isAnimated()

bool QTreeView::isAnimated ( ) const

Definition at line 944 of file qtreeview.cpp.

945 {
946  Q_D(const QTreeView);
947  return d->animationsEnabled;
948 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ isColumnHidden()

bool QTreeView::isColumnHidden ( int  column) const

Returns true if the column is hidden; otherwise returns false.

See also
hideColumn(), isRowHidden()

Definition at line 559 of file qtreeview.cpp.

Referenced by isIndexHidden(), and moveCursor().

560 {
561  Q_D(const QTreeView);
562  return d->header->isSectionHidden(column);
563 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ isExpanded()

bool QTreeView::isExpanded ( const QModelIndex index) const

Returns true if the model item index is expanded; otherwise returns false.

See also
expand(), expanded(), setExpanded()

Definition at line 859 of file qtreeview.cpp.

Referenced by QTreeWidget::isItemExpanded(), QScriptDebuggerLocalsItemDelegate::paint(), scrollTo(), QComboBox::showPopup(), QAccessibleTable2Cell::state(), and timerEvent().

860 {
861  Q_D(const QTreeView);
862  return d->isIndexExpanded(index);
863 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ isFirstColumnSpanned()

bool QTreeView::isFirstColumnSpanned ( int  row,
const QModelIndex parent 
) const

Returns true if the item in first column in the given row of the parent is spanning all the columns; otherwise returns false.

Since
4.3
See also
setFirstColumnSpanned()

Definition at line 651 of file qtreeview.cpp.

Referenced by QTreeWidget::isFirstItemColumnSpanned().

652 {
653  Q_D(const QTreeView);
654  if (d->spanningIndexes.isEmpty() || !d->model)
655  return false;
656  QModelIndex index = d->model->index(row, 0, parent);
657  for (int i = 0; i < d->spanningIndexes.count(); ++i)
658  if (d->spanningIndexes.at(i) == index)
659  return true;
660  return false;
661 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ isHeaderHidden()

bool QTreeView::isHeaderHidden ( ) const

Definition at line 591 of file qtreeview.cpp.

592 {
593  Q_D(const QTreeView);
594  return d->header->isHidden();
595 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ isIndexHidden()

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

Reimplemented Function

Implements QAbstractItemView.

Definition at line 2934 of file qtreeview.cpp.

Referenced by selectedIndexes(), visualRect(), and visualRegionForSelection().

2935 {
2936  return (isColumnHidden(index.column()) || isRowHidden(index.row(), index.parent()));
2937 }
bool isRowHidden(int row, const QModelIndex &parent) const
Returns true if the item in the given row of the parent is hidden; otherwise returns false...
Definition: qtreeview.cpp:609
bool isColumnHidden(int column) const
Returns true if the column is hidden; otherwise returns false.
Definition: qtreeview.cpp:559
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 column() const
Returns the column this model index refers to.

◆ isRowHidden()

bool QTreeView::isRowHidden ( int  row,
const QModelIndex parent 
) const

Returns true if the item in the given row of the parent is hidden; otherwise returns false.

See also
setRowHidden(), isColumnHidden()

Definition at line 609 of file qtreeview.cpp.

Referenced by isIndexHidden(), and QTreeViewPrivate::layout().

610 {
611  Q_D(const QTreeView);
612  if (!d->model)
613  return false;
614  return d->isRowHidden(d->model->index(row, 0, parent));
615 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ isSortingEnabled()

bool QTreeView::isSortingEnabled ( ) const

Definition at line 916 of file qtreeview.cpp.

Referenced by QTreeWidget::isSortingEnabled().

917 {
918  Q_D(const QTreeView);
919  return d->sortingEnabled;
920 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ itemsExpandable()

bool QTreeView::itemsExpandable ( ) const

◆ keyboardSearch()

void QTreeView::keyboardSearch ( const QString search)
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1014 of file qtreeview.cpp.

1015 {
1016  Q_D(QTreeView);
1017  if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root))
1018  return;
1019 
1020  QModelIndex start;
1021  if (currentIndex().isValid())
1022  start = currentIndex();
1023  else
1024  start = d->model->index(0, 0, d->root);
1025 
1026  bool skipRow = false;
1027  bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
1028  qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
1029  if (search.isEmpty() || !keyboardTimeWasValid
1030  || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
1031  d->keyboardInput = search;
1032  skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0)
1033  } else {
1034  d->keyboardInput += search;
1035  }
1036 
1037  // special case for searches with same key like 'aaaaa'
1038  bool sameKey = false;
1039  if (d->keyboardInput.length() > 1) {
1040  int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1));
1041  sameKey = (c == d->keyboardInput.length());
1042  if (sameKey)
1043  skipRow = true;
1044  }
1045 
1046  // skip if we are searching for the same key or a new search started
1047  if (skipRow) {
1048  if (indexBelow(start).isValid())
1049  start = indexBelow(start);
1050  else
1051  start = d->model->index(0, start.column(), d->root);
1052  }
1053 
1054  d->executePostedLayout();
1055  int startIndex = d->viewIndex(start);
1056  if (startIndex <= -1)
1057  return;
1058 
1059  int previousLevel = -1;
1060  int bestAbove = -1;
1061  int bestBelow = -1;
1062  QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput;
1063  for (int i = 0; i < d->viewItems.count(); ++i) {
1064  if ((int)d->viewItems.at(i).level > previousLevel) {
1065  QModelIndex searchFrom = d->viewItems.at(i).index;
1066  if (searchFrom.parent() == start.parent())
1067  searchFrom = start;
1068  QModelIndexList match = d->model->match(searchFrom, Qt::DisplayRole, searchString);
1069  if (match.count()) {
1070  int hitIndex = d->viewIndex(match.at(0));
1071  if (hitIndex >= 0 && hitIndex < startIndex)
1072  bestAbove = bestAbove == -1 ? hitIndex : qMin(hitIndex, bestAbove);
1073  else if (hitIndex >= startIndex)
1074  bestBelow = bestBelow == -1 ? hitIndex : qMin(hitIndex, bestBelow);
1075  }
1076  }
1077  previousLevel = d->viewItems.at(i).level;
1078  }
1079 
1081  if (bestBelow > -1)
1082  index = d->viewItems.at(bestBelow).index;
1083  else if (bestAbove > -1)
1084  index = d->viewItems.at(bestAbove).index;
1085 
1086  if (index.isValid()) {
1087  QItemSelectionModel::SelectionFlags flags = (d->selectionMode == SingleSelection
1088  ? QItemSelectionModel::SelectionFlags(
1090  |d->selectionBehaviorFlags())
1091  : QItemSelectionModel::SelectionFlags(
1093  selectionModel()->setCurrentIndex(index, flags);
1094  }
1095 }
static int keyboardInputInterval()
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static bool match(const uchar *found, const char *target, uint len)
QModelIndex indexBelow(const QModelIndex &index) const
Returns the model index of the item below index.
Definition: qtreeview.cpp:2060
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#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.
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
for(int ii=mo->methodOffset();ii< mo->methodCount();++ii)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QItemSelectionModel * selectionModel() const
Returns the current selection model.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QModelIndex currentIndex() const
Returns the model index of the current item.
__int64 qint64
Definition: qglobal.h:942
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
quint16 index
int column() const
Returns the column this model index refers to.

◆ keyPressEvent()

void QTreeView::keyPressEvent ( QKeyEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1984 of file qtreeview.cpp.

Referenced by QFileDialogTreeView::keyPressEvent().

1985 {
1986  Q_D(QTreeView);
1987  QModelIndex current = currentIndex();
1988  //this is the management of the expansion
1989  if (d->isIndexValid(current) && d->model && d->itemsExpandable) {
1990  switch (event->key()) {
1991  case Qt::Key_Asterisk: {
1992  QStack<QModelIndex> parents;
1993  parents.push(current);
1994  while (!parents.isEmpty()) {
1995  QModelIndex parent = parents.pop();
1996  for (int row = 0; row < d->model->rowCount(parent); ++row) {
1997  QModelIndex child = d->model->index(row, 0, parent);
1998  if (!d->isIndexValid(child))
1999  break;
2000  parents.push(child);
2001  expand(child);
2002  }
2003  }
2004  expand(current);
2005  break; }
2006  case Qt::Key_Plus:
2007  expand(current);
2008  break;
2009  case Qt::Key_Minus:
2010  collapse(current);
2011  break;
2012  }
2013  }
2014 
2016 }
double d
Definition: qnumeric_p.h:62
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
#define Q_D(Class)
Definition: qglobal.h:2482
void collapse(const QModelIndex &index)
Collapses the model item specified by the index.
Definition: qtreeview.cpp:821
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QModelIndex currentIndex() const
Returns the model index of the current item.
void keyPressEvent(QKeyEvent *event)
This function is called with the given event when a key event is sent to the widget.
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
void expand(const QModelIndex &index)
Expands the model item specified by the index.
Definition: qtreeview.cpp:787
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ mouseDoubleClickEvent()

void QTreeView::mouseDoubleClickEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1916 of file qtreeview.cpp.

1917 {
1918  Q_D(QTreeView);
1919  if (state() != NoState || !d->viewport->rect().contains(event->pos()))
1920  return;
1921 
1922  int i = d->itemDecorationAt(event->pos());
1923  if (i == -1) {
1924  i = d->itemAtCoordinate(event->y());
1925  if (i == -1)
1926  return; // user clicked outside the items
1927 
1928  const QPersistentModelIndex firstColumnIndex = d->viewItems.at(i).index;
1929  const QPersistentModelIndex persistent = indexAt(event->pos());
1930 
1931  if (d->pressedIndex != persistent) {
1932  mousePressEvent(event);
1933  return;
1934  }
1935 
1936  // signal handlers may change the model
1937  emit doubleClicked(persistent);
1938 
1939  if (!persistent.isValid())
1940  return;
1941 
1942  if (edit(persistent, DoubleClicked, event) || state() != NoState)
1943  return; // the double click triggered editing
1944 
1946  emit activated(persistent);
1947 
1948  d->executePostedLayout(); // we need to make sure viewItems is updated
1949  if (d->itemsExpandable
1950  && d->expandsOnDoubleClick
1951  && d->hasVisibleChildren(persistent)) {
1952  if (!((i < d->viewItems.count()) && (d->viewItems.at(i).index == firstColumnIndex))) {
1953  // find the new index of the item
1954  for (i = 0; i < d->viewItems.count(); ++i) {
1955  if (d->viewItems.at(i).index == firstColumnIndex)
1956  break;
1957  }
1958  if (i == d->viewItems.count())
1959  return;
1960  }
1961  if (d->viewItems.at(i).expanded)
1962  d->collapse(i, true);
1963  else
1964  d->expand(i, true);
1965  updateGeometries();
1966  viewport()->update();
1967  }
1968  }
1969 }
void mousePressEvent(QMouseEvent *event)
Reimplemented Function
Definition: qtreeview.cpp:1887
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
#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
QStyle * style() const
Definition: qwidget.cpp:2742
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
#define emit
Definition: qobjectdefs.h:76
void activated(const QModelIndex &index)
This signal is emitted when the item specified by index is activated by the user. ...
The QPersistentModelIndex class is used to locate data in a data model.
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:98
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
State state() const
Returns the item view&#39;s state.
void doubleClicked(const QModelIndex &index)
This signal is emitted when a mouse button is double-clicked.
QModelIndex indexAt(const QPoint &p) const
Reimplemented Function
Definition: qtreeview.cpp:2021
bool isValid() const
Returns true if this persistent model index is valid; otherwise returns false.

◆ mouseMoveEvent()

void QTreeView::mouseMoveEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1974 of file qtreeview.cpp.

1975 {
1976  Q_D(QTreeView);
1977  if (d->itemDecorationAt(event->pos()) == -1) // ### what about expanding/collapsing state ?
1979 }
double d
Definition: qnumeric_p.h:62
void mouseMoveEvent(QMouseEvent *event)
This function is called with the given event when a mouse move event is sent to the widget...
#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
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ mousePressEvent()

void QTreeView::mousePressEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1887 of file qtreeview.cpp.

Referenced by mouseDoubleClickEvent().

1888 {
1889  Q_D(QTreeView);
1890  bool handled = false;
1892  handled = d->expandOrCollapseItemAtPos(event->pos());
1893  if (!handled && d->itemDecorationAt(event->pos()) == -1)
1895 }
double d
Definition: qnumeric_p.h:62
#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
QStyle * style() const
Definition: qwidget.cpp:2742
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
const char * styleHint(const QFontDef &request)
void mousePressEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is pressed while the cursor is insid...

◆ mouseReleaseEvent()

void QTreeView::mouseReleaseEvent ( QMouseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1900 of file qtreeview.cpp.

1901 {
1902  Q_D(QTreeView);
1903  if (d->itemDecorationAt(event->pos()) == -1) {
1905  } else {
1909  d->expandOrCollapseItemAtPos(event->pos());
1910  }
1911 }
double d
Definition: qnumeric_p.h:62
#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
QStyle * style() const
Definition: qwidget.cpp:2742
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
const char * styleHint(const QFontDef &request)
State state() const
Returns the item view&#39;s state.
void mouseReleaseEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is released, after a mouse press eve...
void setState(State state)
Sets the item view&#39;s state to the given state.

◆ moveCursor()

QModelIndex QTreeView::moveCursor ( CursorAction  cursorAction,
Qt::KeyboardModifiers  modifiers 
)
protectedvirtual

Move the cursor in the way described by cursorAction, using the information provided by the button modifiers.

Implements QAbstractItemView.

Definition at line 2168 of file qtreeview.cpp.

2169 {
2170  Q_D(QTreeView);
2171  Q_UNUSED(modifiers);
2172 
2173  d->executePostedLayout();
2174 
2175  QModelIndex current = currentIndex();
2176  if (!current.isValid()) {
2177  int i = d->below(-1);
2178  int c = 0;
2179  while (c < d->header->count() && d->header->isSectionHidden(c))
2180  ++c;
2181  if (i < d->viewItems.count() && c < d->header->count()) {
2182  return d->modelIndex(i, c);
2183  }
2184  return QModelIndex();
2185  }
2186  int vi = -1;
2187 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
2188  // Selection behavior is slightly different on the Mac.
2189  if (d->selectionMode == QAbstractItemView::ExtendedSelection
2190  && d->selectionModel
2191  && d->selectionModel->hasSelection()) {
2192 
2193  const bool moveUpDown = (cursorAction == MoveUp || cursorAction == MoveDown);
2194  const bool moveNextPrev = (cursorAction == MoveNext || cursorAction == MovePrevious);
2195  const bool contiguousSelection = moveUpDown && (modifiers & Qt::ShiftModifier);
2196 
2197  // Use the outermost index in the selection as the current index
2198  if (!contiguousSelection && (moveUpDown || moveNextPrev)) {
2199 
2200  // Find outermost index.
2201  const bool useTopIndex = (cursorAction == MoveUp || cursorAction == MovePrevious);
2202  int index = useTopIndex ? INT_MAX : INT_MIN;
2203  const QItemSelection selection = d->selectionModel->selection();
2204  for (int i = 0; i < selection.count(); ++i) {
2205  const QItemSelectionRange &range = selection.at(i);
2206  int candidate = d->viewIndex(useTopIndex ? range.topLeft() : range.bottomRight());
2207  if (candidate >= 0)
2208  index = useTopIndex ? qMin(index, candidate) : qMax(index, candidate);
2209  }
2210 
2211  if (index >= 0 && index < INT_MAX)
2212  vi = index;
2213  }
2214  }
2215 #endif
2216  if (vi < 0)
2217  vi = qMax(0, d->viewIndex(current));
2218 
2219  if (isRightToLeft()) {
2220  if (cursorAction == MoveRight)
2221  cursorAction = MoveLeft;
2222  else if (cursorAction == MoveLeft)
2223  cursorAction = MoveRight;
2224  }
2225  switch (cursorAction) {
2226  case MoveNext:
2227  case MoveDown:
2228 #ifdef QT_KEYPAD_NAVIGATION
2229  if (vi == d->viewItems.count()-1 && QApplication::keypadNavigationEnabled())
2230  return d->model->index(0, current.column(), d->root);
2231 #endif
2232  return d->modelIndex(d->below(vi), current.column());
2233  case MovePrevious:
2234  case MoveUp:
2235 #ifdef QT_KEYPAD_NAVIGATION
2236  if (vi == 0 && QApplication::keypadNavigationEnabled())
2237  return d->modelIndex(d->viewItems.count() - 1, current.column());
2238 #endif
2239  return d->modelIndex(d->above(vi), current.column());
2240  case MoveLeft: {
2242  if (vi < d->viewItems.count() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
2243  d->collapse(vi, true);
2244  d->moveCursorUpdatedView = true;
2245  } else {
2247  if (descend) {
2248  QModelIndex par = current.parent();
2249  if (par.isValid() && par != rootIndex())
2250  return par;
2251  else
2252  descend = false;
2253  }
2254  if (!descend) {
2255  if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2256  int visualColumn = d->header->visualIndex(current.column()) - 1;
2257  while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn)))
2258  visualColumn--;
2259  int newColumn = d->header->logicalIndex(visualColumn);
2260  QModelIndex next = current.sibling(current.row(), newColumn);
2261  if (next.isValid())
2262  return next;
2263  }
2264 
2265  int oldValue = sb->value();
2266  sb->setValue(sb->value() - sb->singleStep());
2267  if (oldValue != sb->value())
2268  d->moveCursorUpdatedView = true;
2269  }
2270 
2271  }
2272  updateGeometries();
2273  viewport()->update();
2274  break;
2275  }
2276  case MoveRight:
2277  if (vi < d->viewItems.count() && !d->viewItems.at(vi).expanded && d->itemsExpandable
2278  && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
2279  d->expand(vi, true);
2280  d->moveCursorUpdatedView = true;
2281  } else {
2283  if (descend) {
2284  QModelIndex idx = d->modelIndex(d->below(vi));
2285  if (idx.parent() == current)
2286  return idx;
2287  else
2288  descend = false;
2289  }
2290  if (!descend) {
2291  if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2292  int visualColumn = d->header->visualIndex(current.column()) + 1;
2293  while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn)))
2294  visualColumn++;
2295 
2296  QModelIndex next = current.sibling(current.row(), visualColumn);
2297  if (next.isValid())
2298  return next;
2299  }
2300 
2301  //last restort: we change the scrollbar value
2303  int oldValue = sb->value();
2304  sb->setValue(sb->value() + sb->singleStep());
2305  if (oldValue != sb->value())
2306  d->moveCursorUpdatedView = true;
2307  }
2308  }
2309  updateGeometries();
2310  viewport()->update();
2311  break;
2312  case MovePageUp:
2313  return d->modelIndex(d->pageUp(vi), current.column());
2314  case MovePageDown:
2315  return d->modelIndex(d->pageDown(vi), current.column());
2316  case MoveHome:
2317  return d->model->index(0, current.column(), d->root);
2318  case MoveEnd:
2319  return d->modelIndex(d->viewItems.count() - 1, current.column());
2320  }
2321  return current;
2322 }
double d
Definition: qnumeric_p.h:62
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
QModelIndex bottomRight() const
Returns the index for the item located at the bottom-right corner of the selection range...
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
int minimum() const
The QItemSelectionRange class manages information about a range of selected items in a model...
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool isColumnHidden(int column) const
Returns true if the column is hidden; otherwise returns false.
Definition: qtreeview.cpp:559
#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.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
QModelIndex topLeft() const
Returns the index for the item located at the top-left corner of the selection range.
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
int value() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QModelIndex currentIndex() const
Returns the model index of the current item.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QItemSelection class manages information about selected items in a model.
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
The QModelIndex class is used to locate data in a data model.
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
int count() const
Returns the number of sections in the header.
quint16 index
int singleStep() const
bool isRightToLeft() const
Definition: qwidget.h:428
QModelIndex rootIndex() const
Returns the model index of the model&#39;s root item.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
#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
#define INT_MAX
int column() const
Returns the column this model index refers to.

◆ paintEvent()

void QTreeView::paintEvent ( QPaintEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1318 of file qtreeview.cpp.

1319 {
1320  Q_D(QTreeView);
1321  d->executePostedLayout();
1322  QPainter painter(viewport());
1323 #ifndef QT_NO_ANIMATION
1324  if (d->isAnimating()) {
1325  drawTree(&painter, event->region() - d->animatedOperation.rect());
1326  d->drawAnimatedOperation(&painter);
1327  } else
1328 #endif //QT_NO_ANIMATION
1329  {
1330  drawTree(&painter, event->region());
1331 #ifndef QT_NO_DRAGANDDROP
1332  d->paintDropIndicator(&painter);
1333 #endif
1334  }
1335 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget * viewport() const
Returns the viewport widget.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
const QRegion & region() const
Returns the region that needs to be updated.
Definition: qevent.h:306
void drawTree(QPainter *painter, const QRegion &region) const
Draws the part of the tree intersecting the given region using the specified painter.
Definition: qtreeview.cpp:1452

◆ reexpand

void QTreeView::reexpand ( )
protectedslot
Warning
This function is not part of the public interface.

Definition at line 2519 of file qtreeview.cpp.

2520 {
2521  // do nothing
2522 }

◆ reset()

void QTreeView::reset ( )
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2113 of file qtreeview.cpp.

2114 {
2115  Q_D(QTreeView);
2116  d->expandedIndexes.clear();
2117  d->hiddenIndexes.clear();
2118  d->spanningIndexes.clear();
2119  d->viewItems.clear();
2121 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
virtual void reset()
Reset the internal state of the view.

◆ resizeColumnToContents

void QTreeView::resizeColumnToContents ( int  column)
slot

Resizes the column given to the size of its contents.

See also
columnWidth(), setColumnWidth()

Definition at line 2613 of file qtreeview.cpp.

Referenced by setHeader().

2614 {
2615  Q_D(QTreeView);
2616  d->executePostedLayout();
2617  if (column < 0 || column >= d->header->count())
2618  return;
2619  int contents = sizeHintForColumn(column);
2620  int header = d->header->isHidden() ? 0 : d->header->sectionSizeHint(column);
2621  d->header->resizeSection(column, qMax(contents, header));
2622 }
double d
Definition: qnumeric_p.h:62
int sizeHintForColumn(int column) const
Returns the size hint for the column&#39;s width or -1 if there is no model.
Definition: qtreeview.cpp:2801
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302

◆ rootIsDecorated()

bool QTreeView::rootIsDecorated ( ) const

Referenced by setIndentation().

◆ rowHeight()

int QTreeView::rowHeight ( const QModelIndex index) const
protected

Returns the height of the row indicated by the given index.

Since
4.3
See also
indexRowSizeHint()

Definition at line 2913 of file qtreeview.cpp.

Referenced by QTreeViewPrivate::paintAlternatingRowColors().

2914 {
2915  Q_D(const QTreeView);
2916  d->executePostedLayout();
2917  int i = d->viewIndex(index);
2918  if (i == -1)
2919  return 0;
2920  return d->itemHeight(i);
2921 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ rowsAboutToBeRemoved()

void QTreeView::rowsAboutToBeRemoved ( const QModelIndex parent,
int  start,
int  end 
)
protectedvirtual

Informs the view that the rows from the start row to the end row inclusive are about to removed from the given parent model item.

Reimplemented from QAbstractItemView.

Definition at line 2566 of file qtreeview.cpp.

2567 {
2568  Q_D(QTreeView);
2570  d->viewItems.clear();
2571 }
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.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
static const KeyPair *const end

◆ rowsInserted()

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

Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item.

Reimplemented from QAbstractItemView.

Definition at line 2528 of file qtreeview.cpp.

2529 {
2530  Q_D(QTreeView);
2531  // if we are going to do a complete relayout anyway, there is no need to update
2532  if (d->delayedPendingLayout) {
2533  QAbstractItemView::rowsInserted(parent, start, end);
2534  return;
2535  }
2536 
2537  //don't add a hierarchy on a column != 0
2538  if (parent.column() != 0 && parent.isValid()) {
2539  QAbstractItemView::rowsInserted(parent, start, end);
2540  return;
2541  }
2542 
2543  const int parentRowCount = d->model->rowCount(parent);
2544  const int delta = end - start + 1;
2545  if (parent != d->root && !d->isIndexExpanded(parent) && parentRowCount > delta) {
2546  QAbstractItemView::rowsInserted(parent, start, end);
2547  return;
2548  }
2549 
2550  const int parentItem = d->viewIndex(parent);
2551  if (((parentItem != -1) && d->viewItems.at(parentItem).expanded)
2552  || (parent == d->root)) {
2553  d->doDelayedItemsLayout();
2554  } else if (parentItem != -1 && (d->model->rowCount(parent) == end - start + 1)) {
2555  // the parent just went from 0 children to more. update to re-paint the decoration
2556  d->viewItems[parentItem].hasChildren = true;
2557  viewport()->update();
2558  }
2559  QAbstractItemView::rowsInserted(parent, start, end);
2560 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
static const KeyPair *const end
int column() const
Returns the column this model index refers to.

◆ rowsRemoved

void QTreeView::rowsRemoved ( const QModelIndex parent,
int  start,
int  end 
)
protectedslot

Informs the view that the rows from the start row to the end row inclusive have been removed from the given parent model item.

Since
4.1

Definition at line 2582 of file qtreeview.cpp.

Referenced by setModel().

2583 {
2584  Q_D(QTreeView);
2585  d->viewItems.clear();
2586  d->doDelayedItemsLayout();
2587  d->hasRemovedItems = true;
2588  d->_q_rowsRemoved(parent, start, end);
2589 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
static const KeyPair *const end

◆ scrollContentsBy()

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

Scrolls the contents of the tree view by (dx, dy).

Reimplemented from QAbstractScrollArea.

Definition at line 2448 of file qtreeview.cpp.

2449 {
2450  Q_D(QTreeView);
2451 
2452  d->delayedAutoScroll.stop(); // auto scroll was canceled by the user scrolling
2453 
2454  dx = isRightToLeft() ? -dx : dx;
2455  if (dx) {
2457  int oldOffset = d->header->offset();
2458  if (horizontalScrollBar()->value() == horizontalScrollBar()->maximum())
2459  d->header->setOffsetToLastSection();
2460  else
2461  d->header->setOffsetToSectionPosition(horizontalScrollBar()->value());
2462  int newOffset = d->header->offset();
2463  dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2464  } else {
2465  d->header->setOffset(horizontalScrollBar()->value());
2466  }
2467  }
2468 
2469  const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
2470  if (d->viewItems.isEmpty() || itemHeight == 0)
2471  return;
2472 
2473  // guestimate the number of items in the viewport
2474  int viewCount = d->viewport->height() / itemHeight;
2475  int maxDeltaY = qMin(d->viewItems.count(), viewCount);
2476  // no need to do a lot of work if we are going to redraw the whole thing anyway
2477  if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) {
2479  d->viewport->update();
2480  return;
2481  }
2482 
2484  int currentScrollbarValue = verticalScrollBar()->value();
2485  int previousScrollbarValue = currentScrollbarValue + dy; // -(-dy)
2486  int currentViewIndex = currentScrollbarValue; // the first visible item
2487  int previousViewIndex = previousScrollbarValue;
2488  const QVector<QTreeViewItem> viewItems = d->viewItems;
2489  dy = 0;
2490  if (previousViewIndex < currentViewIndex) { // scrolling down
2491  for (int i = previousViewIndex; i < currentViewIndex; ++i) {
2492  if (i < d->viewItems.count())
2493  dy -= d->itemHeight(i);
2494  }
2495  } else if (previousViewIndex > currentViewIndex) { // scrolling up
2496  for (int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2497  if (i < d->viewItems.count())
2498  dy += d->itemHeight(i);
2499  }
2500  }
2501  }
2502 
2503  d->scrollContentsBy(dx, dy);
2504 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
ScrollMode horizontalScrollMode() const
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
int value() const
ScrollMode verticalScrollMode() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
bool isRightToLeft() const
Definition: qwidget.h:428
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.

◆ scrollTo()

void QTreeView::scrollTo ( const QModelIndex index,
ScrollHint  hint = EnsureVisible 
)
virtual

Scroll the contents of the tree view until the given model item index is visible.

The hint parameter specifies more precisely where the item should be located after the operation. If any of the parents of the model item are collapsed, they will be expanded to ensure that the model item is visible.

Implements QAbstractItemView.

Definition at line 1141 of file qtreeview.cpp.

Referenced by QTreeWidget::scrollToItem().

1142 {
1143  Q_D(QTreeView);
1144 
1145  if (!d->isIndexValid(index))
1146  return;
1147 
1148  d->executePostedLayout();
1149  d->updateScrollBars();
1150 
1151  // Expand all parents if the parent(s) of the node are not expanded.
1152  QModelIndex parent = index.parent();
1153  while (parent.isValid() && state() == NoState && d->itemsExpandable) {
1154  if (!isExpanded(parent))
1155  expand(parent);
1156  parent = d->model->parent(parent);
1157  }
1158 
1159  int item = d->viewIndex(index);
1160  if (item < 0)
1161  return;
1162 
1163  QRect area = d->viewport->rect();
1164 
1165  // vertical
1167  int top = verticalScrollBar()->value();
1168  int bottom = top + verticalScrollBar()->pageStep();
1169  if (hint == EnsureVisible && item >= top && item < bottom) {
1170  // nothing to do
1171  } else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) {
1172  verticalScrollBar()->setValue(item);
1173  } else { // PositionAtBottom or PositionAtCenter
1174  const int currentItemHeight = d->itemHeight(item);
1175  int y = (hint == PositionAtCenter
1176  //we center on the current item with a preference to the top item (ie. -1)
1177  ? area.height() / 2 + currentItemHeight - 1
1178  //otherwise we simply take the whole space
1179  : area.height());
1180  if (y > currentItemHeight) {
1181  while (item >= 0) {
1182  y -= d->itemHeight(item);
1183  if (y < 0) { //there is no more space left
1184  item++;
1185  break;
1186  }
1187  item--;
1188  }
1189  }
1190  verticalScrollBar()->setValue(item);
1191  }
1192  } else { // ScrollPerPixel
1194  d->coordinateForItem(item), // ### slow for items outside the view
1195  columnWidth(index.column()),
1196  d->itemHeight(item));
1197 
1198  if (rect.isEmpty()) {
1199  // nothing to do
1200  } else if (hint == EnsureVisible && area.contains(rect)) {
1201  d->viewport->update(rect);
1202  // nothing to do
1203  } else {
1204  bool above = (hint == EnsureVisible
1205  && (rect.top() < area.top()
1206  || area.height() < rect.height()));
1207  bool below = (hint == EnsureVisible
1208  && rect.bottom() > area.bottom()
1209  && rect.height() < area.height());
1210 
1211  int verticalValue = verticalScrollBar()->value();
1212  if (hint == PositionAtTop || above)
1213  verticalValue += rect.top();
1214  else if (hint == PositionAtBottom || below)
1215  verticalValue += rect.bottom() - area.height();
1216  else if (hint == PositionAtCenter)
1217  verticalValue += rect.top() - ((area.height() - rect.height()) / 2);
1218  verticalScrollBar()->setValue(verticalValue);
1219  }
1220  }
1221  // horizontal
1222  int viewportWidth = d->viewport->width();
1223  int horizontalOffset = d->header->offset();
1224  int horizontalPosition = d->header->sectionPosition(index.column());
1225  int cellWidth = d->header->sectionSize(index.column());
1226 
1227  if (hint == PositionAtCenter) {
1228  horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
1229  } else {
1230  if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1231  horizontalScrollBar()->setValue(horizontalPosition);
1232  else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
1233  horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
1234  }
1235 }
double d
Definition: qnumeric_p.h:62
int y() const
int columnViewportPosition(int column) const
Returns the horizontal position of the column in the viewport.
Definition: qtreeview.cpp:511
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
Definition: qtreeview.cpp:859
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
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
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
int value() const
ScrollMode verticalScrollMode() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int horizontalOffset() const
Returns the horizontal offset of the items in the treeview.
Definition: qtreeview.cpp:2131
int columnWidth(int column) const
Returns the width of the column.
Definition: qtreeview.cpp:522
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void expand(const QModelIndex &index)
Expands the model item specified by the index.
Definition: qtreeview.cpp:787
QRect rect() const
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
State state() const
Returns the item view&#39;s state.
int pageStep() const
int column() const
Returns the column this model index refers to.
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ selectAll()

void QTreeView::selectAll ( )
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2667 of file qtreeview.cpp.

2668 {
2669  Q_D(QTreeView);
2670  if (!selectionModel())
2671  return;
2672  SelectionMode mode = d->selectionMode;
2673  d->executePostedLayout(); //make sure we lay out the items
2674  if (mode != SingleSelection && !d->viewItems.isEmpty()) {
2675  const QModelIndex &idx = d->viewItems.last().index;
2676  QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1);
2677  d->select(d->viewItems.first().index, lastItemIndex,
2680  }
2681 }
SelectionMode
This enum indicates how the view responds to user selections:
double d
Definition: qnumeric_p.h:62
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
#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.
QItemSelectionModel * selectionModel() const
Returns the current selection model.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
The QModelIndex class is used to locate data in a data model.

◆ selectedIndexes()

QModelIndexList QTreeView::selectedIndexes ( ) const
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2427 of file qtreeview.cpp.

Referenced by QTreeWidget::dropEvent().

2428 {
2429  QModelIndexList viewSelected;
2430  QModelIndexList modelSelected;
2431  if (selectionModel())
2432  modelSelected = selectionModel()->selectedIndexes();
2433  for (int i = 0; i < modelSelected.count(); ++i) {
2434  // check that neither the parents nor the index is hidden before we add
2435  QModelIndex index = modelSelected.at(i);
2436  while (index.isValid() && !isIndexHidden(index))
2437  index = index.parent();
2438  if (index.isValid())
2439  continue;
2440  viewSelected.append(modelSelected.at(i));
2441  }
2442  return viewSelected;
2443 }
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
Definition: qtreeview.cpp:2934
QModelIndexList selectedIndexes() const
Returns a list of all selected model item indexes.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QItemSelectionModel * selectionModel() const
Returns the current selection model.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ selectionChanged()

void QTreeView::selectionChanged ( const QItemSelection selected,
const QItemSelection deselected 
)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 3857 of file qtreeview.cpp.

Referenced by QTreeWidget::QTreeWidget().

3859 {
3860  QAbstractItemView::selectionChanged(selected, deselected);
3861 #ifndef QT_NO_ACCESSIBILITY
3862  if (QAccessible::isActive()) {
3863  // ### does not work properly for selection ranges.
3864  QModelIndex sel = selected.indexes().value(0);
3865  if (sel.isValid()) {
3866 #ifdef Q_WS_X11
3867  int entry = (visualIndex(sel) + (header()?1:0))*sel.model()->columnCount()+sel.column() + 1;
3868  Q_ASSERT(entry > 0);
3870 #else
3871  int entry = visualIndex(sel) + 1;
3872  if (header())
3873  ++entry;
3875 #endif
3876  }
3877  QModelIndex desel = deselected.indexes().value(0);
3878  if (desel.isValid()) {
3879 #ifdef Q_WS_X11
3880  int entry = (visualIndex(desel) + (header()?1:0))*desel.model()->columnCount()+desel.column() + 1;
3881  Q_ASSERT(entry > 0);
3883 #else
3884  int entry = visualIndex(desel) + 1;
3885  if (header())
3886  ++entry;
3888 #endif
3889  }
3890  }
3891 #endif
3892 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QWidget * viewport() const
Returns the viewport widget.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
int visualIndex(const QModelIndex &index) const
Definition: qtreeview.cpp:3894
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
The QModelIndex class is used to locate data in a data model.
QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
int column() const
Returns the column this model index refers to.

◆ setAllColumnsShowFocus()

void QTreeView::setAllColumnsShowFocus ( bool  enable)

Definition at line 964 of file qtreeview.cpp.

965 {
966  Q_D(QTreeView);
967  if (d->allColumnsShowFocus == enable)
968  return;
969  d->allColumnsShowFocus = enable;
970  d->viewport->update();
971 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setAnimated()

void QTreeView::setAnimated ( bool  enable)

Definition at line 938 of file qtreeview.cpp.

939 {
940  Q_D(QTreeView);
941  d->animationsEnabled = animate;
942 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setAutoExpandDelay()

void QTreeView::setAutoExpandDelay ( int  delay)

Definition at line 366 of file qtreeview.cpp.

367 {
368  Q_D(QTreeView);
369  d->autoExpandDelay = delay;
370 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setColumnHidden()

void QTreeView::setColumnHidden ( int  column,
bool  hide 
)

If hide is true the column is hidden, otherwise the column is shown.

See also
hideColumn(), setRowHidden()

Definition at line 570 of file qtreeview.cpp.

571 {
572  Q_D(QTreeView);
573  if (column < 0 || column >= d->header->count())
574  return;
575  d->header->setSectionHidden(column, hide);
576 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void hide()
Hides the widget.
Definition: qwidget.h:501

◆ setColumnWidth()

void QTreeView::setColumnWidth ( int  column,
int  width 
)

Sets the width of the given column to the width specified.

Since
4.2
See also
columnWidth(), resizeColumnToContents()

Definition at line 538 of file qtreeview.cpp.

539 {
540  Q_D(QTreeView);
541  d->header->resizeSection(column, width);
542 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int width() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setExpanded()

void QTreeView::setExpanded ( const QModelIndex index,
bool  expanded 
)

Sets the item referred to by index to either collapse or expanded, depending on the value of expanded.

See also
expanded(), expand(), isExpanded()

Definition at line 871 of file qtreeview.cpp.

Referenced by QTreeWidget::setItemExpanded(), and timerEvent().

872 {
873  if (expanded)
874  this->expand(index);
875  else
876  this->collapse(index);
877 }
void collapse(const QModelIndex &index)
Collapses the model item specified by the index.
Definition: qtreeview.cpp:821
void expanded(const QModelIndex &index)
This signal is emitted when the item specified by index is expanded.
void expand(const QModelIndex &index)
Expands the model item specified by the index.
Definition: qtreeview.cpp:787

◆ setExpandsOnDoubleClick()

void QTreeView::setExpandsOnDoubleClick ( bool  enable)

Definition at line 502 of file qtreeview.cpp.

503 {
504  Q_D(QTreeView);
505  d->expandsOnDoubleClick = enable;
506 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setFirstColumnSpanned()

void QTreeView::setFirstColumnSpanned ( int  row,
const QModelIndex parent,
bool  span 
)

If span is true the item in the first column in the row with the given parent is set to span all columns, otherwise all items on the row are shown.

Since
4.3
See also
isFirstColumnSpanned()

Definition at line 675 of file qtreeview.cpp.

Referenced by QTreeWidget::setFirstItemColumnSpanned().

676 {
677  Q_D(QTreeView);
678  if (!d->model)
679  return;
680  QModelIndex index = d->model->index(row, 0, parent);
681  if (!index.isValid())
682  return;
683 
684  if (span) {
685  QPersistentModelIndex persistent(index);
686  if (!d->spanningIndexes.contains(persistent))
687  d->spanningIndexes.append(persistent);
688  } else {
689  QPersistentModelIndex persistent(index);
690  int i = d->spanningIndexes.indexOf(persistent);
691  if (i >= 0)
692  d->spanningIndexes.remove(i);
693  }
694 
695  d->executePostedLayout();
696  int i = d->viewIndex(index);
697  if (i >= 0)
698  d->viewItems[i].spanning = span;
699 
700  d->viewport->update();
701 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QPersistentModelIndex class is used to locate data in a data model.
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ setHeader()

void QTreeView::setHeader ( QHeaderView header)

Sets the header for the tree view, to the given header.

The view takes ownership over the given header and deletes it when a new header is set.

See also
QAbstractItemModel::headerData()

Definition at line 316 of file qtreeview.cpp.

317 {
318  Q_D(QTreeView);
319  if (header == d->header || !header)
320  return;
321  if (d->header && d->header->parent() == this)
322  delete d->header;
323  d->header = header;
324  d->header->setParent(this);
325 
326  if (!d->header->model()) {
327  d->header->setModel(d->model);
328  if (d->selectionModel)
329  d->header->setSelectionModel(d->selectionModel);
330  }
331 
332  connect(d->header, SIGNAL(sectionResized(int,int,int)),
333  this, SLOT(columnResized(int,int,int)));
334  connect(d->header, SIGNAL(sectionMoved(int,int,int)),
335  this, SLOT(columnMoved()));
336  connect(d->header, SIGNAL(sectionCountChanged(int,int)),
337  this, SLOT(columnCountChanged(int,int)));
338  connect(d->header, SIGNAL(sectionHandleDoubleClicked(int)),
339  this, SLOT(resizeColumnToContents(int)));
340  connect(d->header, SIGNAL(geometriesChanged()),
341  this, SLOT(updateGeometries()));
342 
343  setSortingEnabled(d->sortingEnabled);
344 }
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
#define SLOT(a)
Definition: qobjectdefs.h:226
void resizeColumnToContents(int column)
Resizes the column given to the size of its contents.
Definition: qtreeview.cpp:2613
#define Q_D(Class)
Definition: qglobal.h:2482
#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
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void setSortingEnabled(bool enable)
Definition: qtreeview.cpp:898
void columnResized(int column, int oldSize, int newSize)
This function is called whenever {column}&#39;s size is changed in the header.
Definition: qtreeview.cpp:2756
void columnCountChanged(int oldCount, int newCount)
Informs the tree view that the number of columns in the tree view has changed from oldCount to newCou...
Definition: qtreeview.cpp:2595
void columnMoved()
This slot is called whenever a column has been moved.
Definition: qtreeview.cpp:2509

◆ setHeaderHidden()

void QTreeView::setHeaderHidden ( bool  hide)

Definition at line 597 of file qtreeview.cpp.

598 {
599  Q_D(QTreeView);
600  d->header->setHidden(hide);
601 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void hide()
Hides the widget.
Definition: qwidget.h:501

◆ setIndentation()

void QTreeView::setIndentation ( int  i)

Definition at line 392 of file qtreeview.cpp.

393 {
394  Q_D(QTreeView);
395  if (i != d->indent) {
396  d->indent = i;
397  d->viewport->update();
398  }
399 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setItemsExpandable()

void QTreeView::setItemsExpandable ( bool  enable)

Definition at line 477 of file qtreeview.cpp.

Referenced by QFileDialogTreeView::init().

478 {
479  Q_D(QTreeView);
480  d->itemsExpandable = enable;
481 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setModel()

void QTreeView::setModel ( QAbstractItemModel model)
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Reimplemented in QTreeWidget.

Definition at line 223 of file qtreeview.cpp.

Referenced by QTreeWidget::QTreeWidget().

224 {
225  Q_D(QTreeView);
226  if (model == d->model)
227  return;
228  if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
229  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
230  this, SLOT(rowsRemoved(QModelIndex,int,int)));
231 
232  disconnect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_modelAboutToBeReset()));
233  }
234 
235  if (d->selectionModel) { // support row editing
236  disconnect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
237  d->model, SLOT(submit()));
238  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
239  this, SLOT(rowsRemoved(QModelIndex,int,int)));
240  disconnect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_modelAboutToBeReset()));
241  }
242  d->viewItems.clear();
243  d->expandedIndexes.clear();
244  d->hiddenIndexes.clear();
245  d->header->setModel(model);
247 
248  // QAbstractItemView connects to a private slot
249  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
250  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
251  // do header layout after the tree
252  disconnect(d->model, SIGNAL(layoutChanged()),
253  d->header, SLOT(_q_layoutChanged()));
254  // QTreeView has a public slot for this
255  connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
256  this, SLOT(rowsRemoved(QModelIndex,int,int)));
257 
258  connect(d->model, SIGNAL(modelAboutToBeReset()), SLOT(_q_modelAboutToBeReset()));
259 
260  if (d->sortingEnabled)
261  d->_q_sortIndicatorChanged(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
262 }
double d
Definition: qnumeric_p.h:62
static QAbstractItemModel * staticEmptyModel()
void rowsRemoved(const QModelIndex &parent, int first, int last)
Informs the view that the rows from the start row to the end row inclusive have been removed from the...
Definition: qtreeview.cpp:2582
#define SLOT(a)
Definition: qobjectdefs.h:226
#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
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
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
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
The QModelIndex class is used to locate data in a data model.

◆ setRootIndex()

void QTreeView::setRootIndex ( const QModelIndex index)
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 267 of file qtreeview.cpp.

268 {
269  Q_D(QTreeView);
270  d->header->setRootIndex(index);
272 }
double d
Definition: qnumeric_p.h:62
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setRootIsDecorated()

void QTreeView::setRootIsDecorated ( bool  show)

Definition at line 421 of file qtreeview.cpp.

Referenced by QFileDialogTreeView::init().

422 {
423  Q_D(QTreeView);
424  if (show != d->rootDecoration) {
425  d->rootDecoration = show;
426  d->viewport->update();
427  }
428 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void show()
Shows the widget and its child widgets.

◆ setRowHidden()

void QTreeView::setRowHidden ( int  row,
const QModelIndex parent,
bool  hide 
)

If hide is true the row with the given parent is hidden, otherwise the row is shown.

See also
isRowHidden(), setColumnHidden()

Definition at line 622 of file qtreeview.cpp.

Referenced by QTreeWidget::setItemHidden().

623 {
624  Q_D(QTreeView);
625  if (!d->model)
626  return;
627  QModelIndex index = d->model->index(row, 0, parent);
628  if (!index.isValid())
629  return;
630 
631  if (hide) {
632  d->hiddenIndexes.insert(index);
633  } else if(d->isPersistent(index)) { //if the index is not persistent, it cannot be in the set
634  d->hiddenIndexes.remove(index);
635  }
636 
637  d->doDelayedItemsLayout();
638 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void hide()
Hides the widget.
Definition: qwidget.h:501
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ setSelection()

void QTreeView::setSelection ( const QRect rect,
QItemSelectionModel::SelectionFlags  command 
)
protectedvirtual

Applies the selection command to the items in or touched by the rectangle, rect.

See also
selectionCommand()

Implements QAbstractItemView.

Definition at line 2330 of file qtreeview.cpp.

2331 {
2332  Q_D(QTreeView);
2333  if (!selectionModel() || rect.isNull())
2334  return;
2335 
2336  d->executePostedLayout();
2337  QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right())
2338  : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom()));
2339  QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) :
2340  qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom()));
2341  QModelIndex topLeft = indexAt(tl);
2342  QModelIndex bottomRight = indexAt(br);
2343  if (!topLeft.isValid() && !bottomRight.isValid()) {
2344  if (command & QItemSelectionModel::Clear)
2345  selectionModel()->clear();
2346  return;
2347  }
2348  if (!topLeft.isValid() && !d->viewItems.isEmpty())
2349  topLeft = d->viewItems.first().index;
2350  if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
2351  const int column = d->header->logicalIndex(d->header->count() - 1);
2352  const QModelIndex index = d->viewItems.last().index;
2353  bottomRight = index.sibling(index.row(), column);
2354  }
2355 
2356  if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight))
2357  return;
2358 
2359  d->select(topLeft, bottomRight, command);
2360 }
double d
Definition: qnumeric_p.h:62
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
virtual void clear()
Clears the selection model.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
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
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QItemSelectionModel * selectionModel() const
Returns the current selection model.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QModelIndex class is used to locate data in a data model.
quint16 index
bool isRightToLeft() const
Definition: qwidget.h:428
QModelIndex indexAt(const QPoint &p) const
Reimplemented Function
Definition: qtreeview.cpp:2021

◆ setSelectionModel()

void QTreeView::setSelectionModel ( QItemSelectionModel selectionModel)
virtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Reimplemented in QTreeWidget.

Definition at line 277 of file qtreeview.cpp.

Referenced by QTreeWidget::setSelectionModel().

278 {
279  Q_D(QTreeView);
280  Q_ASSERT(selectionModel);
281  if (d->selectionModel) {
282  // support row editing
283  disconnect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
284  d->model, SLOT(submit()));
285  }
286 
287  d->header->setSelectionModel(selectionModel);
288  QAbstractItemView::setSelectionModel(selectionModel);
289 
290  if (d->selectionModel) {
291  // support row editing
292  connect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
293  d->model, SLOT(submit()));
294  }
295 }
double d
Definition: qnumeric_p.h:62
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
#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
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
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.

◆ setSortingEnabled()

void QTreeView::setSortingEnabled ( bool  enable)

Definition at line 898 of file qtreeview.cpp.

Referenced by QFileDialogTreeView::init(), setHeader(), and QTreeWidget::setSortingEnabled().

899 {
900  Q_D(QTreeView);
901  header()->setSortIndicatorShown(enable);
902  header()->setClickable(enable);
903  if (enable) {
904  //sortByColumn has to be called before we connect or set the sortingEnabled flag
905  // because otherwise it will not call sort on the model.
906  sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
907  connect(header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
908  this, SLOT(_q_sortIndicatorChanged(int,Qt::SortOrder)), Qt::UniqueConnection);
909  } else {
910  disconnect(header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
911  this, SLOT(_q_sortIndicatorChanged(int,Qt::SortOrder)));
912  }
913  d->sortingEnabled = enable;
914 }
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
#define SIGNAL(a)
Definition: qobjectdefs.h:227
SortOrder
Definition: qnamespace.h:189
void setClickable(bool clickable)
If clickable is true, the header will respond to single clicks.
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
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
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
void setSortIndicatorShown(bool show)
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
void sortByColumn(int column, Qt::SortOrder order)
Sets the model up for sorting by the values in the given column and order.
Definition: qtreeview.cpp:2653

◆ setUniformRowHeights()

void QTreeView::setUniformRowHeights ( bool  uniform)

Definition at line 452 of file qtreeview.cpp.

453 {
454  Q_D(QTreeView);
455  d->uniformRowHeights = uniform;
456 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ setWordWrap()

void QTreeView::setWordWrap ( bool  on)

Definition at line 995 of file qtreeview.cpp.

996 {
997  Q_D(QTreeView);
998  if (d->wrapItemText == on)
999  return;
1000  d->wrapItemText = on;
1001  d->doDelayedItemsLayout();
1002 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ showColumn

void QTreeView::showColumn ( int  column)
slot

Shows the given column in the tree view.

See also
hideColumn(), setColumnHidden()

Definition at line 771 of file qtreeview.cpp.

772 {
773  Q_D(QTreeView);
774  d->header->showSection(column);
775 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ sizeHintForColumn()

int QTreeView::sizeHintForColumn ( int  column) const
protectedvirtual

Returns the size hint for the column's width or -1 if there is no model.

If you need to set the width of a given column to a fixed value, call QHeaderView::resizeSection() on the view's header.

If you reimplement this function in a subclass, note that the value you return is only used when resizeColumnToContents() is called. In that case, if a larger column width is required by either the view's header or the item delegate, that width will be used instead.

See also
QWidget::sizeHint, header()

Reimplemented from QAbstractItemView.

Definition at line 2801 of file qtreeview.cpp.

Referenced by resizeColumnToContents().

2802 {
2803  Q_D(const QTreeView);
2804  d->executePostedLayout();
2805  if (d->viewItems.isEmpty())
2806  return -1;
2807  ensurePolished();
2808  int w = 0;
2809  QStyleOptionViewItemV4 option = d->viewOptionsV4();
2810  const QVector<QTreeViewItem> viewItems = d->viewItems;
2811 
2812  int start = 0;
2813  int end = viewItems.count();
2814  if(end > 1000) { //if we have too many item this function would be too slow.
2815  //we get a good approximation by only iterate over 1000 items.
2816  start = qMax(0, d->firstVisibleItem() - 100);
2817  end = qMin(end, start + 900);
2818  }
2819 
2820  for (int i = start; i < end; ++i) {
2821  if (viewItems.at(i).spanning)
2822  continue; // we have no good size hint
2823  QModelIndex index = viewItems.at(i).index;
2824  index = index.sibling(index.row(), column);
2825  QWidget *editor = d->editorForIndex(index).widget.data();
2826  if (editor && d->persistent.contains(editor)) {
2827  w = qMax(w, editor->sizeHint().width());
2828  int min = editor->minimumSize().width();
2829  int max = editor->maximumSize().width();
2830  w = qBound(min, w, max);
2831  }
2832  int hint = d->delegateForIndex(index)->sizeHint(option, index).width();
2833  w = qMax(w, hint + (column == 0 ? d->indentationForItem(i) : 0));
2834  }
2835  return w;
2836 }
double d
Definition: qnumeric_p.h:62
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
QSize minimumSize
the widget&#39;s minimum size
Definition: qwidget.h:172
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
#define Q_D(Class)
Definition: qglobal.h:2482
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
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
The QModelIndex class is used to locate data in a data model.
QModelIndex index
Definition: qtreeview_p.h:68
quint16 index
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
static const KeyPair *const end

◆ sortByColumn() [1/2]

void QTreeView::sortByColumn ( int  column,
Qt::SortOrder  order 
)

Sets the model up for sorting by the values in the given column and order.

Since
4.2

column 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
sortingEnabled

Definition at line 2653 of file qtreeview.cpp.

Referenced by setSortingEnabled(), and sortByColumn().

2654 {
2655  Q_D(QTreeView);
2656 
2657  //If sorting is enabled will emit a signal connected to _q_sortIndicatorChanged, which then actually sorts
2658  d->header->setSortIndicator(column, order);
2659  //If sorting is not enabled, force to sort now.
2660  if (!d->sortingEnabled)
2661  d->model->sort(column, order);
2662 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ sortByColumn [2/2]

void QTreeView::sortByColumn ( int  column)
slot

Sorts the model by the values in the given column.

Definition at line 2633 of file qtreeview.cpp.

2634 {
2635  Q_D(QTreeView);
2636  sortByColumn(column, d->header->sortIndicatorOrder());
2637 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void sortByColumn(int column, Qt::SortOrder order)
Sets the model up for sorting by the values in the given column and order.
Definition: qtreeview.cpp:2653

◆ timerEvent()

void QTreeView::timerEvent ( QTimerEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1240 of file qtreeview.cpp.

1241 {
1242  Q_D(QTreeView);
1243  if (event->timerId() == d->columnResizeTimerID) {
1244  updateGeometries();
1245  killTimer(d->columnResizeTimerID);
1246  d->columnResizeTimerID = 0;
1247  QRect rect;
1248  int viewportHeight = d->viewport->height();
1249  int viewportWidth = d->viewport->width();
1250  for (int i = d->columnsToUpdate.size() - 1; i >= 0; --i) {
1251  int column = d->columnsToUpdate.at(i);
1252  int x = columnViewportPosition(column);
1253  if (isRightToLeft())
1254  rect |= QRect(0, 0, x + columnWidth(column), viewportHeight);
1255  else
1256  rect |= QRect(x, 0, viewportWidth - x, viewportHeight);
1257  }
1258  d->viewport->update(rect.normalized());
1259  d->columnsToUpdate.clear();
1260  } else if (event->timerId() == d->openTimer.timerId()) {
1261  QPoint pos = d->viewport->mapFromGlobal(QCursor::pos());
1263  && d->viewport->rect().contains(pos)) {
1264  QModelIndex index = indexAt(pos);
1265  setExpanded(index, !isExpanded(index));
1266  }
1267  d->openTimer.stop();
1268  }
1269 
1271 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
void updateGeometries()
Reimplemented Function
Definition: qtreeview.cpp:2767
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
void timerEvent(QTimerEvent *event)
This function is called with the given event when a timer event is sent to the widget.
int columnViewportPosition(int column) const
Returns the horizontal position of the column in the viewport.
Definition: qtreeview.cpp:511
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
Definition: qtreeview.cpp:859
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
int columnWidth(int column) const
Returns the width of the column.
Definition: qtreeview.cpp:522
QRect rect() const
int x() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QModelIndex class is used to locate data in a data model.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
State state() const
Returns the item view&#39;s state.
void setExpanded(const QModelIndex &index, bool expand)
Sets the item referred to by index to either collapse or expanded, depending on the value of expanded...
Definition: qtreeview.cpp:871
quint16 index
bool isRightToLeft() const
Definition: qwidget.h:428
QModelIndex indexAt(const QPoint &p) const
Reimplemented Function
Definition: qtreeview.cpp:2021
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ uniformRowHeights()

bool QTreeView::uniformRowHeights ( ) const

◆ updateGeometries()

void QTreeView::updateGeometries ( )
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 2767 of file qtreeview.cpp.

Referenced by collapse(), columnCountChanged(), expand(), expandAll(), expandToDepth(), mouseDoubleClickEvent(), moveCursor(), setHeader(), and timerEvent().

2768 {
2769  Q_D(QTreeView);
2770  if (d->header) {
2771  if (d->geometryRecursionBlock)
2772  return;
2773  d->geometryRecursionBlock = true;
2774  QSize hint = d->header->isHidden() ? QSize(0, 0) : d->header->sizeHint();
2775  setViewportMargins(0, hint.height(), 0, 0);
2776  QRect vg = d->viewport->geometry();
2777  QRect geometryRect(vg.left(), vg.top() - hint.height(), vg.width(), hint.height());
2778  d->header->setGeometry(geometryRect);
2779  //d->header->setOffset(horizontalScrollBar()->value()); // ### bug ???
2780  QMetaObject::invokeMethod(d->header, "updateGeometries");
2781  d->updateScrollBars();
2782  d->geometryRecursionBlock = false;
2783  }
2785 }
double d
Definition: qnumeric_p.h:62
void setViewportMargins(int left, int top, int right, int bottom)
Sets the margins around the scrolling area to left, top, right and bottom.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual void updateGeometries()
Updates the geometry of the child widgets of the view.
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize sizeHint() const
Reimplemented Function

◆ verticalOffset()

int QTreeView::verticalOffset ( ) const
protectedvirtual

Returns the vertical offset of the items in the tree view.

See also
horizontalOffset()

Implements QAbstractItemView.

Definition at line 2142 of file qtreeview.cpp.

Referenced by drawBranches().

2143 {
2144  Q_D(const QTreeView);
2145  if (d->verticalScrollMode == QAbstractItemView::ScrollPerItem) {
2146  if (d->uniformRowHeights)
2147  return verticalScrollBar()->value() * d->defaultItemHeight;
2148  // If we are scrolling per item and have non-uniform row heights,
2149  // finding the vertical offset in pixels is going to be relatively slow.
2150  // ### find a faster way to do this
2151  d->executePostedLayout();
2152  int offset = 0;
2153  for (int i = 0; i < d->viewItems.count(); ++i) {
2154  if (i == verticalScrollBar()->value())
2155  return offset;
2156  offset += d->itemHeight(i);
2157  }
2158  return 0;
2159  }
2160  // scroll per pixel
2161  return verticalScrollBar()->value();
2162 }
double d
Definition: qnumeric_p.h:62
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
#define Q_D(Class)
Definition: qglobal.h:2482
int value() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ viewportEvent()

bool QTreeView::viewportEvent ( QEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemView.

Definition at line 1289 of file qtreeview.cpp.

1290 {
1291  Q_D(QTreeView);
1292  switch (event->type()) {
1293  case QEvent::HoverEnter:
1294  case QEvent::HoverLeave:
1295  case QEvent::HoverMove: {
1296  QHoverEvent *he = static_cast<QHoverEvent*>(event);
1297  int oldBranch = d->hoverBranch;
1298  d->hoverBranch = d->itemDecorationAt(he->pos());
1299  QModelIndex newIndex = indexAt(he->pos());
1300  if (d->hover != newIndex || d->hoverBranch != oldBranch) {
1301  // Update the whole hovered over row. No need to update the old hovered
1302  // row, that is taken care in superclass hover handling.
1303  QRect rect = visualRect(newIndex);
1304  rect.setX(0);
1305  rect.setWidth(viewport()->width());
1306  viewport()->update(rect);
1307  }
1308  break; }
1309  default:
1310  break;
1311  }
1312  return QAbstractItemView::viewportEvent(event);
1313 }
double d
Definition: qnumeric_p.h:62
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QWidget * viewport() const
Returns the viewport widget.
int width() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:282
QRect rect() const
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:131
QRect visualRect(const QModelIndex &index) const
Returns the rectangle on the viewport occupied by the item at index.
Definition: qtreeview.cpp:1101
The QModelIndex class is used to locate data in a data model.
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QModelIndex indexAt(const QPoint &p) const
Reimplemented Function
Definition: qtreeview.cpp:2021
bool event(QEvent *event)
Reimplemented Function
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...

◆ visualIndex()

int QTreeView::visualIndex ( const QModelIndex index) const
private

Definition at line 3894 of file qtreeview.cpp.

Referenced by QTreeViewPrivate::adjustViewOptionsForIndex(), QTreeViewPrivate::calcLogicalIndices(), currentChanged(), indexAt(), and selectionChanged().

3895 {
3896  Q_D(const QTreeView);
3897  d->executePostedLayout();
3898  return d->viewIndex(index);
3899 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58

◆ visualRect()

QRect QTreeView::visualRect ( const QModelIndex index) const
virtual

Returns the rectangle on the viewport occupied by the item at index.

If the index is not visible or explicitly hidden, the returned rectangle is invalid.

Implements QAbstractItemView.

Definition at line 1101 of file qtreeview.cpp.

Referenced by currentChanged(), viewportEvent(), QTreeWidget::visualItemRect(), and visualRegionForSelection().

1102 {
1103  Q_D(const QTreeView);
1104 
1105  if (!d->isIndexValid(index) || isIndexHidden(index))
1106  return QRect();
1107 
1108  d->executePostedLayout();
1109 
1110  int vi = d->viewIndex(index);
1111  if (vi < 0)
1112  return QRect();
1113 
1114  bool spanning = d->viewItems.at(vi).spanning;
1115 
1116  // if we have a spanning item, make the selection stretch from left to right
1117  int x = (spanning ? 0 : columnViewportPosition(index.column()));
1118  int w = (spanning ? d->header->length() : columnWidth(index.column()));
1119  // handle indentation
1120  if (index.column() == 0) {
1121  int i = d->indentationForItem(vi);
1122  w -= i;
1123  if (!isRightToLeft())
1124  x += i;
1125  }
1126 
1127  int y = d->coordinateForItem(vi);
1128  int h = d->itemHeight(vi);
1129 
1130  return QRect(x, y, w, h);
1131 }
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
Definition: qtreeview.cpp:2934
double d
Definition: qnumeric_p.h:62
int y() const
int columnViewportPosition(int column) const
Returns the horizontal position of the column in the viewport.
Definition: qtreeview.cpp:511
#define Q_D(Class)
Definition: qglobal.h:2482
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int columnWidth(int column) const
Returns the width of the column.
Definition: qtreeview.cpp:522
int x() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isRightToLeft() const
Definition: qwidget.h:428
int column() const
Returns the column this model index refers to.

◆ visualRegionForSelection()

QRegion QTreeView::visualRegionForSelection ( const QItemSelection selection) const
protectedvirtual

Returns the rectangle from the viewport of the items in the given selection.

Since 4.7, the returned region only contains rectangles intersecting (or included in) the viewport.

Implements QAbstractItemView.

Definition at line 2369 of file qtreeview.cpp.

2370 {
2371  Q_D(const QTreeView);
2372  if (selection.isEmpty())
2373  return QRegion();
2374 
2375  QRegion selectionRegion;
2376  const QRect &viewportRect = d->viewport->rect();
2377  for (int i = 0; i < selection.count(); ++i) {
2378  QItemSelectionRange range = selection.at(i);
2379  if (!range.isValid())
2380  continue;
2381  QModelIndex parent = range.parent();
2382  QModelIndex leftIndex = range.topLeft();
2383  int columnCount = d->model->columnCount(parent);
2384  while (leftIndex.isValid() && isIndexHidden(leftIndex)) {
2385  if (leftIndex.column() + 1 < columnCount)
2386  leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent);
2387  else
2388  leftIndex = QModelIndex();
2389  }
2390  if (!leftIndex.isValid())
2391  continue;
2392  const QRect leftRect = visualRect(leftIndex);
2393  int top = leftRect.top();
2394  QModelIndex rightIndex = range.bottomRight();
2395  while (rightIndex.isValid() && isIndexHidden(rightIndex)) {
2396  if (rightIndex.column() - 1 >= 0)
2397  rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent);
2398  else
2399  rightIndex = QModelIndex();
2400  }
2401  if (!rightIndex.isValid())
2402  continue;
2403  const QRect rightRect = visualRect(rightIndex);
2404  int bottom = rightRect.bottom();
2405  if (top > bottom)
2406  qSwap<int>(top, bottom);
2407  int height = bottom - top + 1;
2408  if (d->header->sectionsMoved()) {
2409  for (int c = range.left(); c <= range.right(); ++c) {
2410  const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
2411  if (viewportRect.intersects(rangeRect))
2412  selectionRegion += rangeRect;
2413  }
2414  } else {
2415  QRect combined = leftRect|rightRect;
2416  combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
2417  if (viewportRect.intersects(combined))
2418  selectionRegion += combined;
2419  }
2420  }
2421  return selectionRegion;
2422 }
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
Definition: qtreeview.cpp:2934
double d
Definition: qnumeric_p.h:62
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
unsigned char c[8]
Definition: qnumeric_p.h:62
QModelIndex bottomRight() const
Returns the index for the item located at the bottom-right corner of the selection range...
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 columnViewportPosition(int column) const
Returns the horizontal position of the column in the viewport.
Definition: qtreeview.cpp:511
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...
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
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QModelIndex topLeft() const
Returns the index for the item located at the top-left corner of the selection range.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
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 columnWidth(int column) const
Returns the width of the column.
Definition: qtreeview.cpp:522
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:282
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QRect visualRect(const QModelIndex &index) const
Returns the rectangle on the viewport occupied by the item at index.
Definition: qtreeview.cpp:1101
The QModelIndex class is used to locate data in a data model.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isRightToLeft() const
Definition: qwidget.h:428
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
int column() const
Returns the column this model index refers to.

◆ wordWrap()

bool QTreeView::wordWrap ( ) const

Referenced by setWordWrap().

Friends and Related Functions

◆ QAccessibleItemView

friend class QAccessibleItemView
friend

Definition at line 221 of file qtreeview.h.

◆ QAccessibleTable2

friend class QAccessibleTable2
friend

Definition at line 222 of file qtreeview.h.

◆ QAccessibleTable2Cell

Definition at line 224 of file qtreeview.h.

◆ QAccessibleTree

friend class QAccessibleTree
friend

Definition at line 223 of file qtreeview.h.

Properties

◆ allColumnsShowFocus

bool QTreeView::allColumnsShowFocus
private

whether items should show keyboard focus using all columns

Since
4.2

If this property is true all columns will show focus, otherwise only one column will show focus.

The default is false.

Definition at line 68 of file qtreeview.h.

◆ animated

QTreeView::animated
private

whether animations are enabled

Since
4.2

If this property is true the treeview will animate expandsion and collasping of branches. If this property is false, the treeview will expand or collapse branches immediately without showing the animation.

By default, this property is false.

Definition at line 67 of file qtreeview.h.

◆ autoExpandDelay

int QTreeView::autoExpandDelay
private

The delay time before items in a tree are opened during a drag and drop operation.

Since
4.3

This property holds the amount of time in milliseconds that the user must wait over a node before that node will automatically open or close. If the time is set to less then 0 then it will not be activated.

By default, this property has a value of -1, meaning that auto-expansion is disabled.

Definition at line 61 of file qtreeview.h.

◆ expandsOnDoubleClick

bool QTreeView::expandsOnDoubleClick
private

whether the items can be expanded by double-clicking.

Since
4.4

This property holds whether the user can expand and collapse items by double-clicking. The default value is true.

See also
itemsExpandable

Definition at line 71 of file qtreeview.h.

◆ headerHidden

QTreeView::headerHidden
private

whether the header is shown or not.

Since
4.4

If this property is true, the header is not shown otherwise it is. The default value is false.

See also
header()

Definition at line 70 of file qtreeview.h.

◆ indentation

int QTreeView::indentation
private

indentation of the items in the tree view.

This property holds the indentation measured in pixels of the items for each level in the tree view. For top-level items, the indentation specifies the horizontal distance from the viewport edge to the items in the first column; for child items, it specifies their indentation from their parent items.

By default, this property has a value of 20.

Definition at line 62 of file qtreeview.h.

◆ itemsExpandable

bool QTreeView::itemsExpandable
private

whether the items are expandable by the user.

This property holds whether the user can expand and collapse items interactively.

By default, this property is true.

Definition at line 65 of file qtreeview.h.

◆ rootIsDecorated

bool QTreeView::rootIsDecorated
private

whether to show controls for expanding and collapsing top-level items

Items with children are typically shown with controls to expand and collapse them, allowing their children to be shown or hidden. If this property is false, these controls are not shown for top-level items. This can be used to make a single level tree structure appear like a simple list of items.

By default, this property is true.

Definition at line 63 of file qtreeview.h.

◆ sortingEnabled

QTreeView::sortingEnabled
private

whether sorting is enabled

Since
4.2

If this property is true, sorting is enabled for the tree; if the property is false, sorting is not enabled. The default value is false.

Note
In order to avoid performance issues, it is recommended that sorting is enabled after inserting the items into the tree. Alternatively, you could also insert the items into a list before inserting the items into the tree.
See also
sortByColumn()

Definition at line 66 of file qtreeview.h.

◆ uniformRowHeights

bool QTreeView::uniformRowHeights
private

whether all items in the treeview have the same height

This property should only be set to true if it is guaranteed that all items in the view has the same height. This enables the view to do some optimizations.

The height is obtained from the first item in the view. It is updated when the data changes on that item.

By default, this property is false.

Definition at line 64 of file qtreeview.h.

◆ wordWrap

bool QTreeView::wordWrap
private

the item text word-wrapping policy

Since
4.3

If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is false by default.

Note that even if wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current QAbstractItemView::textElideMode.

Definition at line 69 of file qtreeview.h.


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