QAbstractItemView 类

QAbstractItemView 类为项视图类提供基本功能。 更多...

头: #include <QAbstractItemView>
qmake: QT += widgets
继承: QAbstractScrollArea
继承者:

QColumnView , QHeaderView , QListView , QTableView ,和 QTreeView

公共类型

enum DragDropMode { NoDragDrop, DragOnly, DropOnly, DragDrop, InternalMove }
enum EditTrigger { NoEditTriggers, CurrentChanged, DoubleClicked, SelectedClicked, ..., AllEditTriggers }
flags EditTriggers
enum ScrollHint { EnsureVisible, PositionAtTop, PositionAtBottom, PositionAtCenter }
enum ScrollMode { ScrollPerItem, ScrollPerPixel }
enum SelectionBehavior { SelectItems, SelectRows, SelectColumns }
enum SelectionMode { SingleSelection, ContiguousSelection, ExtendedSelection, MultiSelection, NoSelection }

特性

公共函数

QAbstractItemView (QWidget * parent = Q_NULLPTR)
~QAbstractItemView ()
bool alternatingRowColors () const
int autoScrollMargin () const
void closePersistentEditor (const QModelIndex & index )
QModelIndex currentIndex () const
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
virtual QModelIndex indexAt (const QPoint & point ) const = 0
QWidget * indexWidget (const QModelIndex & index ) const
QAbstractItemDelegate * itemDelegate () const
QAbstractItemDelegate * itemDelegate (const QModelIndex & index ) const
QAbstractItemDelegate * itemDelegateForColumn (int column ) const
QAbstractItemDelegate * itemDelegateForRow (int row ) const
virtual void keyboardSearch (const QString & search )
QAbstractItemModel * model () const
void openPersistentEditor (const QModelIndex & index )
void resetHorizontalScrollMode ()
void resetVerticalScrollMode ()
QModelIndex rootIndex () const
virtual void scrollTo (const QModelIndex & index , ScrollHint hint = EnsureVisible) = 0
QAbstractItemView::SelectionBehavior selectionBehavior () const
QAbstractItemView::SelectionMode selectionMode () const
QItemSelectionModel * selectionModel () const
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 )
void setItemDelegate (QAbstractItemDelegate * delegate )
void setItemDelegateForColumn (int column , QAbstractItemDelegate * delegate )
void setItemDelegateForRow (int row , QAbstractItemDelegate * delegate )
virtual void setModel (QAbstractItemModel * model )
void setSelectionBehavior (QAbstractItemView::SelectionBehavior behavior )
void setSelectionMode (QAbstractItemView::SelectionMode mode )
virtual void setSelectionModel (QItemSelectionModel * selectionModel )
void setTabKeyNavigation (bool enable )
void setTextElideMode (Qt::TextElideMode mode )
void setVerticalScrollMode (ScrollMode mode )
bool showDropIndicator () const
virtual int sizeHintForColumn (int column ) const
QSize sizeHintForIndex (const QModelIndex & index ) const
virtual int sizeHintForRow (int row ) const
bool tabKeyNavigation () const
Qt::TextElideMode textElideMode () const
ScrollMode verticalScrollMode () const
virtual QRect visualRect (const QModelIndex & index ) const = 0

重实现公共函数

virtual QVariant inputMethodQuery (Qt::InputMethodQuery query ) const

公共槽

void clearSelection ()
void edit (const QModelIndex & index )
virtual void reset ()
void scrollToBottom ()
void scrollToTop ()
virtual void selectAll ()
void setCurrentIndex (const QModelIndex & index )
virtual void setRootIndex (const QModelIndex & index )
void update (const QModelIndex & index )

信号

void activated (const QModelIndex & index )
void clicked (const QModelIndex & index )
void doubleClicked (const QModelIndex & index )
void entered (const QModelIndex & index )
void iconSizeChanged (const QSize & size )
void pressed (const QModelIndex & index )
void viewportEntered ()

保护类型

enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight, ..., MovePrevious }
enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport }
enum State { NoState, DraggingState, DragSelectingState, EditingState, ..., AnimatingState }

保护函数

QPoint dirtyRegionOffset () const
DropIndicatorPosition dropIndicatorPosition () const
virtual bool edit (const QModelIndex & index , EditTrigger trigger , QEvent * event )
void executeDelayedItemsLayout ()
virtual int horizontalOffset () const = 0
virtual bool isIndexHidden (const QModelIndex & index ) const = 0
virtual QModelIndex moveCursor (CursorAction cursorAction , Qt::KeyboardModifiers modifiers ) = 0
void scheduleDelayedItemsLayout ()
void scrollDirtyRegion (int dx , int dy )
virtual QModelIndexList selectedIndexes () const
virtual QItemSelectionModel::SelectionFlags selectionCommand (const QModelIndex & index , const QEvent * event = Q_NULLPTR) const
void setDirtyRegion (const QRegion & region )
virtual void setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags flags ) = 0
void setState (State state )
virtual void startDrag (Qt::DropActions supportedActions )
State state () const
virtual int verticalOffset () const = 0
virtual QStyleOptionViewItem viewOptions () const
virtual QRegion visualRegionForSelection (const QItemSelection & selection ) const = 0

重实现保护函数

virtual void dragEnterEvent (QDragEnterEvent * event )
virtual void dragLeaveEvent (QDragLeaveEvent * event )
virtual void dragMoveEvent (QDragMoveEvent * event )
virtual void dropEvent (QDropEvent * event )
virtual bool event (QEvent * event )
virtual void focusInEvent (QFocusEvent * event )
virtual bool focusNextPrevChild (bool next )
virtual void focusOutEvent (QFocusEvent * event )
virtual void inputMethodEvent (QInputMethodEvent * event )
virtual void keyPressEvent (QKeyEvent * event )
virtual void mouseDoubleClickEvent (QMouseEvent * event )
virtual void mouseMoveEvent (QMouseEvent * event )
virtual void mousePressEvent (QMouseEvent * event )
virtual void mouseReleaseEvent (QMouseEvent * event )
virtual void resizeEvent (QResizeEvent * event )
virtual void timerEvent (QTimerEvent * event )
virtual bool viewportEvent (QEvent * event )
virtual QSize viewportSizeHint () const

保护槽

virtual void closeEditor (QWidget * editor , QAbstractItemDelegate::EndEditHint hint )
virtual void commitData (QWidget * editor )
virtual void currentChanged (const QModelIndex & current , const QModelIndex & previous )
virtual void dataChanged (const QModelIndex & topLeft , const QModelIndex & bottomRight , const QVector<int> & roles = QVector<int> ())
virtual void editorDestroyed (QObject * editor )
virtual void rowsAboutToBeRemoved (const QModelIndex & parent , int start , int end )
virtual void rowsInserted (const QModelIndex & parent , int start , int end )
virtual void selectionChanged (const QItemSelection & selected , const QItemSelection & deselected )
virtual void updateGeometries ()

额外继承成员

详细描述

QAbstractItemView 类为项视图类提供基本功能。

QAbstractItemView class is the base class for every standard view that uses a QAbstractItemModel . QAbstractItemView is an abstract class and cannot itself be instantiated. It provides a standard interface for interoperating with models through the signals and slots mechanism, enabling subclasses to be kept up-to-date with changes to their models. This class provides standard support for keyboard and mouse navigation, viewport scrolling, item editing, and selections. The keyboard navigation implements this functionality:

功能
方向键 改变当前项并选择它。
Ctrl + 方向键 改变当前项但不选择它。
Shift + 方向键 更改当前项并选择它。先前选中项不会被取消选择。
Ctr+Space 触发当前项的选定。
Tab/Backtab 将当前项更改为下一/上一项。
Home/End 选择模型中的第一/最后项。
Page up/Page down 按视图中的可见行数向上/向下卷动展示行。
Ctrl+A 选择模型中的所有项。

注意,上表假定 选定模式 允许操作。例如,无法选择项,若选定模式为 QAbstractItemView::NoSelection .

QAbstractItemView 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .

视图类继承 QAbstractItemView only need to implement their own view-specific functionality, such as drawing items, returning the geometry of items, finding items, etc.

QAbstractItemView provides common slots such as edit () 和 setCurrentIndex ()。还提供很多保护槽,包括 dataChanged (), rowsInserted (), rowsAboutToBeRemoved (), selectionChanged (),和 currentChanged ().

根项的返回通过 rootIndex (),和当前项通过 currentIndex ()。要确保项可见使用 scrollTo ().

Some of QAbstractItemView 's functions are concerned with scrolling, for example setHorizontalScrollMode () 和 setVerticalScrollMode ()。要设置滚动条的范围,例如,可以重实现视图的 resizeEvent () 函数:

void MyView::resizeEvent(QResizeEvent *event) {
    horizontalScrollBar()->setRange(0, realWidth - width());
    ...
}
					

注意,范围不更新,直到小部件被展示为止。

几个其它函数涉及选定控制;例如 setSelectionMode (),和 setSelectionBehavior ()。此类为处理提供默认选定模型 ( selectionModel ()),但可以替换这通过使用 setSelectionModel () 采用实例 QItemSelectionModel .

要完全控制项的显示和编辑,可以指定委托采用 setItemDelegate ().

QAbstractItemView provides a lot of protected functions. Some are concerned with editing, for example, edit (),和 commitData (),而其它的是键盘和鼠标事件处理程序。

注意: If you inherit QAbstractItemView and intend to update the contents of the viewport, you should use viewport-> update () 而不是 update() 因为所有描绘操作都发生在视口中。

另请参阅 视图类 , 模型/视图编程 , QAbstractItemModel ,和 图表范例 .

成员类型文档编制

enum QAbstractItemView:: CursorAction

此枚举描述在项之间导航的不同方式,

常量 描述
QAbstractItemView::MoveUp 0 移至当前项的上方项。
QAbstractItemView::MoveDown 1 移至当前项的下方项。
QAbstractItemView::MoveLeft 2 移动到当前项的左侧项。
QAbstractItemView::MoveRight 3 移动到当前项的右侧项。
QAbstractItemView::MoveHome 4 移至左上角项。
QAbstractItemView::MoveEnd 5 移动到右下角项。
QAbstractItemView::MovePageUp 6 移至当前项上一页。
QAbstractItemView::MovePageDown 7 移至当前项下一页。
QAbstractItemView::MoveNext 8 移至当前项之后项。
QAbstractItemView::MovePrevious 9 移至当前项之前项。

另请参阅 moveCursor ().

enum QAbstractItemView:: DragDropMode

描述视图可以行动的各种拖放事件。默认情况下,视图不支持拖曳或掉落 ( NoDragDrop ).

常量 描述
QAbstractItemView::NoDragDrop 0 不支持拖曳或掉落。
QAbstractItemView::DragOnly 1 视图支持拖曳自己的项
QAbstractItemView::DropOnly 2 视图接受掉落
QAbstractItemView::DragDrop 3 视图支持拖拽和掉落两者
QAbstractItemView::InternalMove 4 视图接受移动 ( 非拷贝 ) 操作仅来自自身。

注意,使用模型需要提供对拖放操作的支持。

该枚举在 Qt 4.2 引入或被修改。

另请参阅 setDragDropMode () 和 将拖放用于项视图 .

enum QAbstractItemView:: DropIndicatorPosition

此枚举指示掉落指示器相对当前鼠标位置的索引位置:

常量 描述
QAbstractItemView::OnItem 0 项将掉落在索引处。
QAbstractItemView::AboveItem 1 项将掉落在索引上方。
QAbstractItemView::BelowItem 2 项将掉落在索引下方。
QAbstractItemView::OnViewport 3 项将掉落在没有项的视口区域。各视图处理视口掉落项的方式,从属正使用的底层模型行为。

enum QAbstractItemView:: EditTrigger
flags QAbstractItemView:: EditTriggers

此枚举描述将初始项编辑的动作。

常量 描述
QAbstractItemView::NoEditTriggers 0 没有编辑可能。
QAbstractItemView::CurrentChanged 1 开始编辑每当当前项改变时。
QAbstractItemView::DoubleClicked 2 开始编辑当双击项时。
QAbstractItemView::SelectedClicked 4 开始编辑当点击已选中项时。
QAbstractItemView::EditKeyPressed 8 开始编辑当在项上按下平台编辑键时。
QAbstractItemView::AnyKeyPressed 16 开始编辑当在项上按下任意键时。
QAbstractItemView::AllEditTriggers 31 开始编辑对于上述所有动作。

EditTriggers 类型是 typedef 对于 QFlags <EditTrigger>。它存储 EditTrigger 值的 OR 组合。

enum QAbstractItemView:: ScrollHint

常量 描述
QAbstractItemView::EnsureVisible 0 卷动以确保项可见。
QAbstractItemView::PositionAtTop 1 卷动以将项放置在视口顶部。
QAbstractItemView::PositionAtBottom 2 卷动以定位到视口底部项。
QAbstractItemView::PositionAtCenter 3 卷动以定位到视口中心项。

enum QAbstractItemView:: ScrollMode

描述滚动条的行为应如何。当把卷动模式设为 ScrollPerPixel 时,将自动调节单步大小,除非它被明确设置使用 setSingleStep() 。可以通过将单步大小设为 -1 以还原自动调节。

常量 描述
QAbstractItemView::ScrollPerItem 0 视图每次卷动内容一项。
QAbstractItemView::ScrollPerPixel 1 视图每次卷动内容一像素。

该枚举在 Qt 4.2 引入或被修改。

enum QAbstractItemView:: SelectionBehavior

常量 描述
QAbstractItemView::SelectItems 0 选择单个项。
QAbstractItemView::SelectRows 1 仅选择行。
QAbstractItemView::SelectColumns 2 仅选择列。

enum QAbstractItemView:: SelectionMode

此枚举指示视图如何响应用户选择:

常量 描述
QAbstractItemView::SingleSelection 1 When the user selects an item, any already-selected item becomes unselected. It is possible for the user to deselect the selected item.
QAbstractItemView::ContiguousSelection 4 当用户以通常方式选择项时,清零选定并选中新项。不管怎样,若用户按下 Shift 键点击项,选中 (或取消选中) 当前项和点击项之间的所有项,从属点击项状态。
QAbstractItemView::ExtendedSelection 3 当用户以通常方式选择项时,清零选定并选中新项。不管怎样,若用户按下 Ctrl 键点击项时,触发点击项,而所有其它项保持原样。若用户按下 Shift 键点击项,选中 (或取消选中) 当前项和点击项之间的所有项,从属点击项状态。可以通过拖曳鼠标到多个项之上来选择它们。
QAbstractItemView::MultiSelection 2 当用户以通常方式选择项时,会触发这些项的选定状态,而其它项单独保持。可以通过拖曳鼠标到多个项之上来触发它们。
QAbstractItemView::NoSelection 0 无法选择项。

最常用模式为 SingleSelection 和 ExtendedSelection。

enum QAbstractItemView:: State

描述视图可以处于的不同状态。通常,这只对重实现自己的视图感兴趣。

常量 描述
QAbstractItemView::NoState 0 这是默认状态。
QAbstractItemView::DraggingState 1 用户正在拖曳项。
QAbstractItemView::DragSelectingState 2 用户正在选择项。
QAbstractItemView::EditingState 3 用户正在 Widget 编辑器中编辑项。
QAbstractItemView::ExpandingState 4 用户正在打开项分支。
QAbstractItemView::CollapsingState 5 用户正在关闭项分支。
QAbstractItemView::AnimatingState 6 项视图正在履行动画。

特性文档编制

alternatingRowColors : bool

此特性保持是否使用交替颜色绘制背景

若此特性为 true ,将绘制项背景使用 QPalette::Base and QPalette::AlternateBase ;否则将绘制项背景使用 QPalette::Base 颜色。

默认情况下此特性为 false .

访问函数:

bool alternatingRowColors () const
void setAlternatingRowColors (bool enable )

autoScroll : bool

此特性保持是否在拖拽移动事件中启用自动卷动

若此特性被设为 true (默认), QAbstractItemView 自动卷动视图内容,若用户在视口边缘 16 像素内拖曳。若当前项改变,那么视图将自动滚动以确保当前项完全可见。

此特性才工作,若视口接受掉落。通过将此特性设为 false 以关闭自动卷动。

访问函数:

bool hasAutoScroll () const
void setAutoScroll (bool enable )

autoScrollMargin : int

此特性保持区域的大小当触发自动卷动时

此特性控制视口边缘触发自动滚动的区域大小。默认值为 16 像素。

该特性在 Qt 4.4 引入。

访问函数:

int autoScrollMargin () const
void setAutoScrollMargin (int margin )

defaultDropAction : Qt::DropAction

此特性保持将默认用于 QAbstractItemView::drag() 的掉落动作

若特性未设置,掉落动作为 CopyAction 当支持的动作支持 CopyAction 时。

该特性在 Qt 4.6 引入。

访问函数:

Qt::DropAction defaultDropAction () const
void setDefaultDropAction (Qt::DropAction dropAction )

另请参阅 showDropIndicator and dragDropOverwriteMode .

dragDropMode : DragDropMode

此特性保持视图将进行拖放事件行动

该特性在 Qt 4.2 引入。

访问函数:

DragDropMode dragDropMode () const
void setDragDropMode (DragDropMode behavior )

另请参阅 showDropIndicator and dragDropOverwriteMode .

dragDropOverwriteMode : bool

此特性保持视图的拖放行为

若其值为 true , the selected data will overwrite the existing item data when dropped, while moving the data will clear the item. If its value is false , the selected data will be inserted as a new item when the data is dropped. When the data is moved, the item is removed as well.

默认值为 false ,作为在 QListView and QTreeView 子类。在 QTableView 子类,另一方面,特性已被设为 true .

Note: This is not intended to prevent overwriting of items. The model's implementation of flags() should do that by not returning Qt::ItemIsDropEnabled .

该特性在 Qt 4.2 引入。

访问函数:

bool dragDropOverwriteMode () const
void setDragDropOverwriteMode (bool overwrite )

另请参阅 dragDropMode .

dragEnabled : bool

此特性保持视图是否支持拖拽其自己的项

访问函数:

bool dragEnabled () const
void setDragEnabled (bool enable )

另请参阅 showDropIndicator , DragDropMode , dragDropOverwriteMode ,和 acceptDrops .

editTriggers : EditTriggers

This property holds which actions will initiate item editing

This property is a selection of flags defined by EditTrigger , combined using the OR operator. The view will only initiate the editing of an item if the action performed is set in this property.

访问函数:

EditTriggers editTriggers () const
void setEditTriggers (EditTriggers triggers )

horizontalScrollMode : ScrollMode

视图如何在水平方向卷动其内容

此特性控制视图如何水平卷动其内容。卷动可以按像素或按项进行。它的默认值来自样式凭借 QStyle::SH_ItemView_ScrollMode 样式提示。

该特性在 Qt 4.2 引入。

访问函数:

ScrollMode horizontalScrollMode () const
void setHorizontalScrollMode (ScrollMode mode )
void resetHorizontalScrollMode ()

iconSize : QSize

此特性保持项图标的大小

设置此特性将导致项被再次布置,当视图可见时。

访问函数:

QSize iconSize () const
void setIconSize (const QSize & size )

通知程序信号:

void iconSizeChanged (const QSize & size )

selectionBehavior : SelectionBehavior

此特性保持视图使用的选定行为

此特性保持是否按单项、单行或单列进行选择。

访问函数:

QAbstractItemView::SelectionBehavior selectionBehavior () const
void setSelectionBehavior (QAbstractItemView::SelectionBehavior behavior )

另请参阅 SelectionMode and SelectionBehavior .

selectionMode : SelectionMode

此特性保持在哪种选择模式下操作视图

此特性控制用户是否可以选择一个或多个项,和在多项选定中,选定是否必须为连续范围项。

访问函数:

QAbstractItemView::SelectionMode selectionMode () const
void setSelectionMode (QAbstractItemView::SelectionMode mode )

另请参阅 SelectionMode and SelectionBehavior .

showDropIndicator : bool

此特性保持是否展示掉落指示器,当拖放项时。

访问函数:

bool showDropIndicator () const
void setDropIndicatorShown (bool enable )

另请参阅 dragEnabled , DragDropMode , dragDropOverwriteMode ,和 acceptDrops .

tabKeyNavigation : bool

此特性保持采用 tab 和 backtab 的项导航是否被启用。

访问函数:

bool tabKeyNavigation () const
void setTabKeyNavigation (bool enable )

textElideMode : Qt::TextElideMode

此特性保持 ... 在省略文本中的位置。

所有项视图的默认值为 Qt::ElideRight .

访问函数:

Qt::TextElideMode textElideMode () const
void setTextElideMode (Qt::TextElideMode mode )

verticalScrollMode : ScrollMode

视图如何在垂直方向卷动其内容

此特性控制视图如何垂直卷动其内容。卷动可以按每像素或每项进行。它的默认值来自样式凭借 QStyle::SH_ItemView_ScrollMode 样式提示。

该特性在 Qt 4.2 引入。

访问函数:

ScrollMode verticalScrollMode () const
void setVerticalScrollMode (ScrollMode mode )
void resetVerticalScrollMode ()

成员函数文档编制

QAbstractItemView:: QAbstractItemView ( QWidget * parent = Q_NULLPTR)

构造抽象项视图采用给定 parent .

QAbstractItemView:: ~QAbstractItemView ()

销毁视图。

[signal] void QAbstractItemView:: activated (const QModelIndex & index )

此信号被发射当项指定通过 index is activated by the user. How to activate items depends on the platform; e.g., by single- or double-clicking the item, or by pressing the Return or Enter key when the item is current.

另请参阅 clicked (), doubleClicked (), entered (),和 pressed ().

[slot] void QAbstractItemView:: clearSelection ()

Deselects all selected items. The current index will not be changed.

另请参阅 setSelection () 和 selectAll ().

[signal] void QAbstractItemView:: clicked (const QModelIndex & index )

This signal is emitted when a mouse button is left-clicked. The item the mouse was clicked on is specified by index . The signal is only emitted when the index is valid.

另请参阅 activated (), doubleClicked (), entered (),和 pressed ().

[virtual protected slot] void QAbstractItemView:: closeEditor ( QWidget * editor , QAbstractItemDelegate::EndEditHint hint )

关闭给定 editor , and releases it. The hint is used to specify how the view should respond to the end of the editing operation. For example, the hint may indicate that the next item in the view should be opened for editing.

另请参阅 edit () 和 commitData ().

void QAbstractItemView:: closePersistentEditor (const QModelIndex & index )

关闭用于项的持久编辑器在给定 index .

另请参阅 openPersistentEditor ().

[virtual protected slot] void QAbstractItemView:: commitData ( QWidget * editor )

提交数据在 editor 到模型。

另请参阅 closeEditor ().

[virtual protected slot] void QAbstractItemView:: currentChanged (const QModelIndex & current , const QModelIndex & previous )

This slot is called when a new item becomes the current item. The previous current item is specified by the previous index, and the new item by the current index.

If you want to know about changes to items see the dataChanged () 信号。

QModelIndex QAbstractItemView:: currentIndex () const

返回当前项的模型索引。

另请参阅 setCurrentIndex ().

[virtual protected slot] void QAbstractItemView:: dataChanged (const QModelIndex & topLeft , const QModelIndex & bottomRight , const QVector < int > & roles = QVector<int> ())

This slot is called when items with the given roles are changed in the model. The changed items are those from topLeft to bottomRight inclusive. If just one item is changed topLeft == bottomRight .

roles which have been changed can either be an empty container (meaning everything has changed), or a non-empty container with the subset of roles which have changed.

[protected] QPoint QAbstractItemView:: dirtyRegionOffset () const

返回视图脏区域的偏移。

若使用 scrollDirtyRegion () 和实现 paintEvent () 在子类化的 QAbstractItemView ,应采用由此函数返回的偏移,翻译由描绘事件给出的区域。

另请参阅 scrollDirtyRegion () 和 setDirtyRegion ().

[signal] void QAbstractItemView:: doubleClicked (const QModelIndex & index )

This signal is emitted when a mouse button is double-clicked. The item the mouse was double-clicked on is specified by index . The signal is only emitted when the index is valid.

另请参阅 clicked () 和 activated ().

[virtual protected] void QAbstractItemView:: dragEnterEvent ( QDragEnterEvent * event )

重实现自 QWidget::dragEnterEvent ().

此函数被调用采用给定 event when a drag and drop operation enters the widget. If the drag is over a valid dropping place (e.g. over an item that accepts drops), the event is accepted; otherwise it is ignored.

另请参阅 dropEvent () 和 startDrag ().

[virtual protected] void QAbstractItemView:: dragLeaveEvent ( QDragLeaveEvent * event )

重实现自 QWidget::dragLeaveEvent ().

This function is called when the item being dragged leaves the view. The event describes the state of the drag and drop operation.

[virtual protected] void QAbstractItemView:: dragMoveEvent ( QDragMoveEvent * event )

重实现自 QWidget::dragMoveEvent ().

This function is called continuously with the given event during a drag and drop operation over the widget. It can cause the view to scroll if, for example, the user drags a selection to view's right or bottom edge. In this case, the event will be accepted; otherwise it will be ignored.

另请参阅 dropEvent () 和 startDrag ().

[virtual protected] void QAbstractItemView:: dropEvent ( QDropEvent * event )

重实现自 QWidget::dropEvent ().

此函数被调用采用给定 event 当掉落事件出现在 Widget 上时。若模型接受事件位置,接受掉落事件;否则,忽略。

另请参阅 startDrag ().

[protected] DropIndicatorPosition QAbstractItemView:: dropIndicatorPosition () const

Returns the position of the drop indicator in relation to the closest item.

该函数在 Qt 4.1 引入。

[slot] void QAbstractItemView:: edit (const QModelIndex & index )

Starts editing the item corresponding to the given index 若它可编辑。

Note that this function does not change the current index. Since the current index defines the next and previous items to edit, users may find that keyboard navigation does not work as expected. To provide consistent navigation behavior, call setCurrentIndex () 在此函数采用相同模型索引之前。

另请参阅 QModelIndex::flags ().

[virtual protected] bool QAbstractItemView:: edit (const QModelIndex & index , EditTrigger trigger , QEvent * event )

Starts editing the item at index , creating an editor if necessary, and returns true 若视图的 State 现为 EditingState ;否则返回 false .

The action that caused the editing process is described by trigger , and the associated event is specified by event .

Editing can be forced by specifying the trigger QAbstractItemView::AllEditTriggers .

另请参阅 closeEditor ().

[virtual protected slot] void QAbstractItemView:: editorDestroyed ( QObject * editor )

This function is called when the given editor has been destroyed.

另请参阅 closeEditor ().

[signal] void QAbstractItemView:: entered (const QModelIndex & index )

This signal is emitted when the mouse cursor enters the item specified by index . Mouse tracking needs to be enabled for this feature to work.

另请参阅 viewportEntered (), activated (), clicked (), doubleClicked (),和 pressed ().

[virtual protected] bool QAbstractItemView:: event ( QEvent * event )

重实现自 QObject::event ().

[protected] void QAbstractItemView:: executeDelayedItemsLayout ()

执行调度布局,不等待事件处理开始。

另请参阅 scheduleDelayedItemsLayout ().

[virtual protected] void QAbstractItemView:: focusInEvent ( QFocusEvent * event )

重实现自 QWidget::focusInEvent ().

此函数被调用采用给定 event when the widget obtains the focus. By default, the event is ignored.

另请参阅 setFocus () 和 focusOutEvent ().

[virtual protected] bool QAbstractItemView:: focusNextPrevChild ( bool next )

重实现自 QWidget::focusNextPrevChild ().

[virtual protected] void QAbstractItemView:: focusOutEvent ( QFocusEvent * event )

重实现自 QWidget::focusOutEvent ().

此函数被调用采用给定 event when the widget looses the focus. By default, the event is ignored.

另请参阅 clearFocus () 和 focusInEvent ().

[pure virtual protected] int QAbstractItemView:: horizontalOffset () const

返回视图的水平偏移。

在基类中,这是纯虚函数。

另请参阅 verticalOffset ().

[pure virtual] QModelIndex QAbstractItemView:: indexAt (const QPoint & point ) const

Returns the model index of the item at the viewport coordinates point .

在基类中,这是纯虚函数。

另请参阅 visualRect ().

QWidget *QAbstractItemView:: indexWidget (const QModelIndex & index ) const

返回用于项的 Widget 在给定 index .

该函数在 Qt 4.1 引入。

另请参阅 setIndexWidget ().

[virtual protected] void QAbstractItemView:: inputMethodEvent ( QInputMethodEvent * event )

重实现自 QWidget::inputMethodEvent ().

[virtual] QVariant QAbstractItemView:: inputMethodQuery ( Qt::InputMethodQuery query ) const

重实现自 QWidget::inputMethodQuery ().

[pure virtual protected] bool QAbstractItemView:: isIndexHidden (const QModelIndex & index ) const

返回 true 若项引用通过给定 index is hidden in the view, otherwise returns false .

Hiding is a view specific feature. For example in TableView a column can be marked as hidden or a row in the TreeView .

在基类中,这是纯虚函数。

QAbstractItemDelegate *QAbstractItemView:: itemDelegate () const

Returns the item delegate used by this view and model. This is either one set with setItemDelegate (), or the default one.

另请参阅 setItemDelegate ().

QAbstractItemDelegate *QAbstractItemView:: itemDelegate (const QModelIndex & index ) const

Returns the item delegate used by this view and model for the given index .

QAbstractItemDelegate *QAbstractItemView:: itemDelegateForColumn ( int column ) const

Returns the item delegate used by this view and model for the given column 。可以调用 itemDelegate () to get a pointer to the current delegate for a given index.

该函数在 Qt 4.2 引入。

另请参阅 setItemDelegateForColumn (), itemDelegateForRow (),和 itemDelegate ().

QAbstractItemDelegate *QAbstractItemView:: itemDelegateForRow ( 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. You can call itemDelegate () to get a pointer to the current delegate for a given index.

该函数在 Qt 4.2 引入。

另请参阅 setItemDelegateForRow (), itemDelegateForColumn (),和 setItemDelegate ().

[virtual protected] void QAbstractItemView:: keyPressEvent ( QKeyEvent * event )

重实现自 QWidget::keyPressEvent ().

此函数被调用采用给定 event when a key event is sent to the widget. The default implementation handles basic cursor movement, e.g. Up, Down, Left, Right, Home, PageUp, and PageDown; the activated () signal is emitted if the current index is valid and the activation key is pressed (e.g. Enter or Return, depending on the platform). This function is where editing is initiated by key press, e.g. if F2 is pressed.

另请参阅 edit (), moveCursor (), keyboardSearch (),和 tabKeyNavigation .

[virtual] void QAbstractItemView:: keyboardSearch (const QString & search )

Moves to and selects the item best matching the string search . If no item is found nothing happens.

In the default implementation, the search is reset if search is empty, or the time interval since the last search has exceeded QApplication::keyboardInputInterval ().

QAbstractItemModel *QAbstractItemView:: model () const

Returns the model that this view is presenting.

另请参阅 setModel ().

[virtual protected] void QAbstractItemView:: mouseDoubleClickEvent ( QMouseEvent * event )

重实现自 QWidget::mouseDoubleClickEvent ().

此函数被调用采用给定 event when a mouse button is double clicked inside the widget. If the double-click is on a valid item it emits the doubleClicked () signal and calls edit () on the item.

[virtual protected] void QAbstractItemView:: mouseMoveEvent ( QMouseEvent * event )

重实现自 QWidget::mouseMoveEvent ().

此函数被调用采用给定 event when a mouse move event is sent to the widget. If a selection is in progress and new items are moved over the selection is extended; if a drag is in progress it is continued.

[virtual protected] void QAbstractItemView:: mousePressEvent ( QMouseEvent * event )

重实现自 QWidget::mousePressEvent ().

此函数被调用采用给定 event when a mouse button is pressed while the cursor is inside the widget. If a valid item is pressed on it is made into the current item. This function emits the pressed () 信号。

[virtual protected] void QAbstractItemView:: mouseReleaseEvent ( QMouseEvent * event )

重实现自 QWidget::mouseReleaseEvent ().

此函数被调用采用给定 event when a mouse button is released, after a mouse press event on the widget. If a user presses the mouse inside your widget and then drags the mouse to another location before releasing the mouse button, your widget receives the release event. The function will emit the clicked () signal if an item was being pressed.

[pure virtual protected] QModelIndex QAbstractItemView:: moveCursor ( CursorAction cursorAction , Qt::KeyboardModifiers modifiers )

返回 QModelIndex 对象指向下一视图对象,基于给定 cursorAction and keyboard modifiers specified by modifiers .

在基类中,这是纯虚函数。

void QAbstractItemView:: openPersistentEditor (const QModelIndex & index )

Opens a persistent editor on the item at the given index . If no editor exists, the delegate will create a new editor.

另请参阅 closePersistentEditor ().

[signal] void QAbstractItemView:: pressed (const QModelIndex & index )

This signal is emitted when a mouse button is pressed. The item the mouse was pressed on is specified by index . The signal is only emitted when the index is valid.

使用 QApplication::mouseButtons () function to get the state of the mouse buttons.

另请参阅 activated (), clicked (), doubleClicked (),和 entered ().

[virtual slot] void QAbstractItemView:: reset ()

重置视图的内部状态。

警告: This function will reset open editors, scroll bar positions, selections, etc. Existing changes will not be committed. If you would like to save your changes when resetting the view, you can reimplement this function, commit your changes, and then call the superclass' implementation.

[virtual protected] void QAbstractItemView:: resizeEvent ( QResizeEvent * event )

重实现自 QWidget::resizeEvent ().

此函数被调用采用给定 event 当重置大小事件被发送给 Widget 时。

另请参阅 QWidget::resizeEvent ().

QModelIndex QAbstractItemView:: rootIndex () const

Returns the model index of the model's root item. The root item is the parent item to the view's toplevel items. The root can be invalid.

另请参阅 setRootIndex ().

[virtual protected slot] void QAbstractItemView:: rowsAboutToBeRemoved (const QModelIndex & parent , int start , int end )

This slot is called when rows are about to be removed. The deleted rows are those under the given parent from start to end 包含在内。

另请参阅 rowsInserted ().

[virtual protected slot] void QAbstractItemView:: rowsInserted (const QModelIndex & parent , int start , int end )

This slot is called when rows are inserted. The new rows are those under the given parent from start to end inclusive. The base class implementation calls fetchMore() on the model to check for more data.

另请参阅 rowsAboutToBeRemoved ().

[protected] void QAbstractItemView:: scheduleDelayedItemsLayout ()

Schedules a layout of the items in the view to be executed when the event processing starts.

Even if scheduleDelayedItemsLayout() is called multiple times before events are processed, the view will only do the layout once.

另请参阅 executeDelayedItemsLayout ().

[protected] void QAbstractItemView:: scrollDirtyRegion ( int dx , int dy )

准备卷动视图按 ( dx , dy ) 像素通过沿相反方向移动脏区域。只需调用此函数,若在视图子类中实现卷动视口。

若实现 scrollContentsBy () 在子类化的 QAbstractItemView ,调用此函数先于调用 QWidget::scroll () 在视口。另外,仅仅调用 update ().

另请参阅 scrollContentsBy (), dirtyRegionOffset (),和 setDirtyRegion ().

[pure virtual] void QAbstractItemView:: scrollTo (const QModelIndex & index , ScrollHint hint = EnsureVisible)

卷动视图若有必要确此项在 index 可见。视图将试着定位项根据给定 hint .

在基类中,这是纯虚函数。

[slot] void QAbstractItemView:: scrollToBottom ()

卷动视图到底部。

该函数在 Qt 4.1 引入。

另请参阅 scrollTo () 和 scrollToTop ().

[slot] void QAbstractItemView:: scrollToTop ()

卷动视图到顶部。

该函数在 Qt 4.1 引入。

另请参阅 scrollTo () 和 scrollToBottom ().

[virtual slot] void QAbstractItemView:: selectAll ()

Selects all items in the view. This function will use the selection behavior set on the view when selecting.

另请参阅 setSelection (), selectedIndexes (),和 clearSelection ().

[virtual protected] QModelIndexList QAbstractItemView:: selectedIndexes () const

This convenience function returns a list of all selected and non-hidden item indexes in the view. The list contains no duplicates, and is not sorted.

另请参阅 QItemSelectionModel::selectedIndexes ().

[virtual protected slot] void QAbstractItemView:: selectionChanged (const QItemSelection & selected , const QItemSelection & deselected )

This slot is called when the selection is changed. The previous selection (which may be empty), is specified by deselected , and the new selection by selected .

另请参阅 setSelection ().

[virtual protected] QItemSelectionModel::SelectionFlags QAbstractItemView:: selectionCommand (const QModelIndex & index , const QEvent * event = Q_NULLPTR) const

Returns the SelectionFlags to be used when updating a selection with to include the index specified. The event is a user input event, such as a mouse or keyboard event.

重实现此函数以定义自己的选择行为。

另请参阅 setSelection ().

QItemSelectionModel *QAbstractItemView:: selectionModel () const

返回当前选定模型。

另请参阅 setSelectionModel () 和 selectedIndexes ().

[slot] void QAbstractItemView:: setCurrentIndex (const QModelIndex & index )

将当前项设为是项在 index .

除非当前选定方式为 NoSelection ,项也会被选中。注意:此函数还会更新用户履行任何新选定的起始位置。

要把项设为当前项而不选择它,调用

selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);

另请参阅 currentIndex (), currentChanged (),和 selectionMode .

[protected] void QAbstractItemView:: setDirtyRegion (const QRegion & region )

标记给定 region 为脏并调度它以更新。只需调用此函数,若正在实现自己的视图子类。

该函数在 Qt 4.1 引入。

另请参阅 scrollDirtyRegion () 和 dirtyRegionOffset ().

void QAbstractItemView:: setIndexWidget (const QModelIndex & index , QWidget * widget )

设置给定 widget on the item at the given index , passing the ownership of the widget to the viewport.

index 无效 (如:若传递根索引),此函数什么都不做。

给定 widget 's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the item at the given index .

If index widget A is replaced with index widget B, index widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted.

setIndexWidget(index, new QLineEdit);
...
setIndexWidget(index, new QTextEdit);
					

This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate 代替。

该函数在 Qt 4.1 引入。

另请参阅 indexWidget () 和 委托类 .

void QAbstractItemView:: setItemDelegate ( QAbstractItemDelegate * delegate )

Sets the item delegate for this view and its model to delegate . This is useful if you want complete control over the editing and display of items.

任何现有委托将被移除,但不被删除。 QAbstractItemView 未拥有所有权对于 delegate .

警告: You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the closeEditor() 信号,并尝试访问、修改或关闭已关闭的编辑器。

另请参阅 itemDelegate ().

void QAbstractItemView:: setItemDelegateForColumn ( int column , QAbstractItemDelegate * delegate )

Sets the given item delegate used by this view and model for the given column . All items on column will be drawn and managed by delegate instead of using the default delegate (i.e., itemDelegate ()).

Any existing column delegate for column will be removed, but not deleted. QAbstractItemView 未拥有所有权对于 delegate .

注意: If a delegate has been assigned to both a row and a column, the row delegate will take precedence and manage the intersecting cell index.

警告: You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the closeEditor() 信号,并尝试访问、修改或关闭已关闭的编辑器。

该函数在 Qt 4.2 引入。

另请参阅 itemDelegateForColumn (), setItemDelegateForRow (),和 itemDelegate ().

void QAbstractItemView:: setItemDelegateForRow ( int row , QAbstractItemDelegate * delegate )

Sets the given item delegate used by this view and model for the given row . All items on row will be drawn and managed by delegate instead of using the default delegate (i.e., itemDelegate ()).

Any existing row delegate for row will be removed, but not deleted. QAbstractItemView 未拥有所有权对于 delegate .

注意: If a delegate has been assigned to both a row and a column, the row delegate (i.e., this delegate) will take precedence and manage the intersecting cell index.

警告: You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the closeEditor() 信号,并尝试访问、修改或关闭已关闭的编辑器。

该函数在 Qt 4.2 引入。

另请参阅 itemDelegateForRow (), setItemDelegateForColumn (),和 itemDelegate ().

[virtual] void QAbstractItemView:: setModel ( QAbstractItemModel * model )

设置 model for the view to present.

This function will create and set a new selection model, replacing any model that was previously set with setSelectionModel (). However, the old selection model will not be deleted as it may be shared between several views. We recommend that you delete the old selection model if it is no longer required. This is done with the following code:

QItemSelectionModel *m = view->selectionModel();
view->setModel(new model);
delete m;
					

If both the old model and the old selection model do not have parents, or if their parents are long-lived objects, it may be preferable to call their deleteLater () functions to explicitly delete them.

The view does not take ownership of the model unless it is the model's parent object because the model may be shared between many different views.

另请参阅 model (), selectionModel (),和 setSelectionModel ().

[virtual slot] void QAbstractItemView:: setRootIndex (const QModelIndex & index )

Sets the root item to the item at the given index .

另请参阅 rootIndex ().

[pure virtual protected] void QAbstractItemView:: setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags flags )

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

When implementing your own itemview setSelection should call selectionModel ()->select(selection, flags) where selection is either an empty QModelIndex QItemSelection that contains all items that are contained in rect .

另请参阅 selectionCommand () 和 selectedIndexes ().

[virtual] void QAbstractItemView:: setSelectionModel ( QItemSelectionModel * selectionModel )

Sets the current selection model to the given selectionModel .

Note that, if you call setModel () after this function, the given selectionModel will be replaced by one created by the view.

注意: It is up to the application to delete the old selection model if it is no longer needed; i.e., if it is not being used by other views. This will happen automatically when its parent object is deleted. However, if it does not have a parent, or if the parent is a long-lived object, it may be preferable to call its deleteLater () function to explicitly delete it.

另请参阅 selectionModel (), setModel (),和 clearSelection ().

[protected] void QAbstractItemView:: setState ( State state )

将项视图的状态设为给定 state .

另请参阅 state ().

[virtual] int QAbstractItemView:: sizeHintForColumn ( int column ) const

返回宽度大小提示为指定 column 或 -1 若没有模型。

此函数用于具有水平 Header 头的视图,以查找 Header 头区间的大小提示基于内容为给定 column .

另请参阅 sizeHintForRow ().

QSize QAbstractItemView:: sizeHintForIndex (const QModelIndex & index ) const

返回大小提示为项采用指定 index 或无效大小对于无效索引。

另请参阅 sizeHintForRow () 和 sizeHintForColumn ().

[virtual] int QAbstractItemView:: sizeHintForRow ( int row ) const

返回高度大小提示为指定 row 或 -1 若没有模型。

The returned height is calculated using the size hints of the given row 's items, i.e. the returned value is the maximum height among the items. Note that to control the height of a row, you must reimplement the QAbstractItemDelegate::sizeHint () 函数。

This function is used in views with a vertical header to find the size hint for a header section based on the contents of the given row .

另请参阅 sizeHintForColumn ().

[virtual protected] void QAbstractItemView:: startDrag ( Qt::DropActions supportedActions )

开始拖拽通过调用 drag->exec() 使用给定 supportedActions .

[protected] State QAbstractItemView:: state () const

返回项视图的状态。

另请参阅 setState ().

[virtual protected] void QAbstractItemView:: timerEvent ( QTimerEvent * event )

重实现自 QObject::timerEvent ().

此函数被调用采用给定 event 当计时器事件被发送给 Widget 时。

另请参阅 QObject::timerEvent ().

[slot] void QAbstractItemView:: update (const QModelIndex & index )

Updates the area occupied by the given index .

该函数在 Qt 4.3 引入。

[virtual protected slot] void QAbstractItemView:: updateGeometries ()

更新视图子级 Widget 的几何体。

该函数在 Qt 4.4 引入。

[pure virtual protected] int QAbstractItemView:: verticalOffset () const

返回视图的垂直偏移。

在基类中,这是纯虚函数。

另请参阅 horizontalOffset ().

[virtual protected] QStyleOptionViewItem QAbstractItemView:: viewOptions () const

返回 QStyleOptionViewItem structure populated with the view's palette, font, state, alignments etc.

[signal] void QAbstractItemView:: viewportEntered ()

This signal is emitted when the mouse cursor enters the viewport. Mouse tracking needs to be enabled for this feature to work.

另请参阅 entered ().

[virtual protected] bool QAbstractItemView:: viewportEvent ( QEvent * event )

重实现自 QAbstractScrollArea::viewportEvent ().

此函数用于处理工具提示和 What's This? 模式,若给定 event QEvent::ToolTip ,或 QEvent::WhatsThis 。它将所有其它事件传递到其基类 viewportEvent() 处理程序。

[virtual protected] QSize QAbstractItemView:: viewportSizeHint () const

重实现自 QAbstractScrollArea::viewportSizeHint ().

该函数在 Qt 5.2 引入。

[pure virtual] QRect QAbstractItemView:: visualRect (const QModelIndex & index ) const

返回项所占据的视口矩形为 index .

若项显示在多个区域,那么 visualRect 应返回包含索引的首要区域,而不是索引可能环绕、触摸或导致绘制的完整区域。

在基类中,这是纯虚函数。

另请参阅 indexAt () 和 visualRegionForSelection ().

[pure virtual protected] QRegion QAbstractItemView:: visualRegionForSelection (const QItemSelection & selection ) const

返回来自项视口的区域在给定 selection .

在基类中,这是纯虚函数。

另请参阅 visualRect () 和 selectedIndexes ().