QAbstractItemView 類

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

額外繼承成員

詳細描述

The QAbstractItemView 類為項視圖類提供基本功能。

QAbstractItemView 類是每個標準視圖的基類使用 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 .

The QAbstractItemView 類是一種 模型/視圖類 且屬於 Qt 的 模型/視圖框架 .

視圖類繼承 QAbstractItemView 隻需要實現自己的特定視圖功能,譬如繪製項、返迴項幾何體、查找項、等。

QAbstractItemView 提供常見槽,譬如 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 當用戶選擇項時,任何已選中項變為被取消選擇。用戶取消選中項的選擇是可能的。
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 ,選中數據將覆寫現有項數據當掉落時,而移動數據時將清除項。若其值為 false ,選中數據將插入作為新項當數據掉落時。當數據移動時,項也被移除。

默認值為 false ,作為在 QListView and QTreeView 子類。在 QTableView 子類,另一方麵,特性已被設為 true .

注意:這並非旨在阻止項覆寫。模型的 flags() 實現應做到這點,通過不返迴 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

此特性保持動作將初啓項編輯

此特性選定的標誌定義通過 EditTrigger ,使用 OR 運算符組閤。視圖纔初始項的編輯,若此特性有設置履行動作。

訪問函數:

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 被用戶激活。如何激活項從屬平颱;如:單擊 (或雙擊) 項,或按下 Return/Enter 鍵在項為當前時。

另請參閱 clicked (), doubleClicked (), entered (),和 pressed ().

[slot] void QAbstractItemView:: clearSelection ()

取消所有選中項的選擇。當前索引不會改變。

另請參閱 setSelection () 和 selectAll ().

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

此信號發射,當點擊鼠標左按鈕時。鼠標點擊項的指定是通過 index 。信號纔發射,當索引有效時。

另請參閱 activated (), doubleClicked (), entered (),和 pressed ().

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

關閉給定 editor 並釋放它。 hint 用於指定視圖應如何響應編輯操作的結束。例如,hint (提示) 可能指示應打開下一視圖項以供編輯。

另請參閱 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 )

此槽被調用,當新項變為當前項。上一當前項的指定通過 previous 索引,和新項通過 current 索引。

若想要知道項的有關改變,見 dataChanged () 信號。

QModelIndex QAbstractItemView:: currentIndex () const

返迴當前項的模型索引。

另請參閱 setCurrentIndex ().

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

此槽被調用,當項具有給定 roles 在模型中被改變。那些改變項來自 topLeft to bottomRight (包括在內)。若僅僅改變 1 項 topLeft == bottomRight .

The roles (已改變) 可以是空容器 (意味著一切都已改變),或是帶有已改變角色子集的非空容器。

[protected] QPoint QAbstractItemView:: dirtyRegionOffset () const

返迴視圖髒區域的偏移。

若使用 scrollDirtyRegion () 和實現 paintEvent () 在子類化的 QAbstractItemView ,應采用由此函數返迴的偏移,翻譯由描繪事件給齣的區域。

另請參閱 scrollDirtyRegion () 和 setDirtyRegion ().

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

此信號被發射,當雙擊鼠標按鈕時。被鼠標雙擊項的指定是通過 index 。信號纔發射,當索引有效時。

另請參閱 clicked () 和 activated ().

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

重實現自 QWidget::dragEnterEvent ().

此函數被調用采用給定 event 當拖放操作進入 Widget 時。若拖拽到有效掉落位置 (如:在接受掉落的項上),事件被接受;否則,事件被忽略。

另請參閱 dropEvent () 和 startDrag ().

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

重實現自 QWidget::dragLeaveEvent ().

此函數被調用,當被拖拽項離開視圖時。 event 描述拖放操作的狀態。

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

重實現自 QWidget::dragMoveEvent ().

會連續調用此函數采用給定 event 當拖放操作在 Widget 上時。它會導緻視圖捲動, 例如:用戶拖拽選定到視圖右側 (或底部邊緣)。在此情況下,事件被接受;否則,事件被忽略。

另請參閱 dropEvent () 和 startDrag ().

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

重實現自 QWidget::dropEvent ().

此函數被調用采用給定 event 當掉落事件齣現在 Widget 上時。若模型接受事件位置,接受掉落事件;否則,忽略。

另請參閱 startDrag ().

[protected] DropIndicatorPosition QAbstractItemView:: dropIndicatorPosition () const

返迴掉落指示器相對於最近項的位置。

該函數在 Qt 4.1 引入。

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

開始編輯的項對應給定 index 若它可編輯。

注意,此函數不改變當前索引。由於當前索引定義瞭要編輯的下一和上一項,因此用戶可能發現鍵盤導航無法如期望般工作。要提供一緻導航行為,調用 setCurrentIndex () 在此函數采用相同模型索引之前。

另請參閱 QModelIndex::flags ().

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

開始編輯的項在 index ,創建編輯器若有必要,並返迴 true 若視圖的 State 現為 EditingState ;否則返迴 false .

導緻編輯過程動作的描述是通過 trigger ,且關聯事件的指定是通過 event .

可以強製編輯通過指定 trigger QAbstractItemView::AllEditTriggers .

另請參閱 closeEditor ().

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

此函數被調用當給定 editor 已被銷毀。

另請參閱 closeEditor ().

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

此信號發射,當鼠標光標進入的項指定通過 index 。需要啓用鼠標追蹤,為使此特徵能工作。

另請參閱 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 當 Widget 獲得聚焦時。默認情況下,事件被忽略。

另請參閱 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

返迴項模型索引在視口坐標 point .

在基類中,這是純虛函數。

另請參閱 visualRect ().

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

返迴用於項的 Widget 在給定 index .

該函數在 Qt 4.1 引入。

另請參閱 setIndexWidget ().

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

重實現自 QWidget::inputMethodEvent ().

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

重實現自 QWidget::inputMethodQuery ().

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

返迴 true 若項引用通過給定 index 在視圖中被隱藏,否則返迴 false .

隱藏特定視圖特性。例如在 TableView 中列可以被標記為隱藏,或行在 TreeView .

在基類中,這是純虛函數。

QAbstractItemDelegate *QAbstractItemView:: itemDelegate () const

返迴此視圖和模型使用的項委托。這是某個設置采用 setItemDelegate (),或默認的。

另請參閱 setItemDelegate ().

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

返迴用於此視圖的項委托和模型為給定 index .

QAbstractItemDelegate *QAbstractItemView:: itemDelegateForColumn ( int column ) const

返迴用於此視圖的項委托和模型為給定 column 。可以調用 itemDelegate () 以獲取用於給定索引的當前委托指針。

該函數在 Qt 4.2 引入。

另請參閱 setItemDelegateForColumn (), itemDelegateForRow (),和 itemDelegate ().

QAbstractItemDelegate *QAbstractItemView:: itemDelegateForRow ( int row ) const

返迴用於此視圖的項委托和模型為給定 row , or 0 if no delegate has been assigned. You can call itemDelegate () 以獲取用於給定索引的當前委托指針。

該函數在 Qt 4.2 引入。

另請參閱 setItemDelegateForRow (), itemDelegateForColumn (),和 setItemDelegate ().

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

重實現自 QWidget::keyPressEvent ().

此函數被調用采用給定 event 當將鍵事件發送給 Widget 時。默認實現處理基本光標移動 (如:Up、Down、Left、Right、Home、PageUp、PageDown); activated () 信號被發射,若當前索引有效且激活鍵被按下 (如 Enter 或 Return,從屬平颱)。此函數是通過按下鍵初啓編輯 (如:若按下 F2)。

另請參閱 edit (), moveCursor (), keyboardSearch (),和 tabKeyNavigation .

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

移動到並選擇項最佳匹配字符串 search 。若找不到項,什麼都不發生。

按默認實現,搜索被重置若 search 為空,或從最後一次搜索起的時間間隔有超過 QApplication::keyboardInputInterval ().

QAbstractItemModel *QAbstractItemView:: model () const

返迴此視圖呈現的模型。

另請參閱 setModel ().

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

重實現自 QWidget::mouseDoubleClickEvent ().

此函數被調用采用給定 event 當在 Widget 內雙擊鼠標按鈕時。若雙擊有效項,會發射 doubleClicked () 信號和調用 edit () 在項。

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

重實現自 QWidget::mouseMoveEvent ().

此函數被調用采用給定 event 當把鼠標移動事件發送給 Widget 時。若選擇正在進行中,且要覆蓋選定而移動新項,將擴展;若拖拽正在進行中,繼續。

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

重實現自 QWidget::mousePressEvent ().

此函數被調用采用給定 event 當按下鼠標按鈕 (且光標在 Widget 內部) 時。若被按下,有效項會變成當前項。此函數發射 pressed () 信號。

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

重實現自 QWidget::mouseReleaseEvent ().

此函數被調用采用給定 event 當鼠標按鈕被釋放時,在 Widget 鼠標按下事件後。若用戶在 Widget 內按下鼠標,然後將鼠標拖拽到另一位置在釋放鼠標按鈕前,Widget 收到釋放事件。此函數會發射 clicked () 信號若項被按下。

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

返迴 QModelIndex 對象指嚮下一視圖對象,基於給定 cursorAction 和鍵盤修飾符指定通過 modifiers .

在基類中,這是純虛函數。

void QAbstractItemView:: openPersistentEditor (const QModelIndex & index )

打開項持久編輯器在給定 index 。若不存在編輯器,委托將創建新的編輯器。

另請參閱 closePersistentEditor ().

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

此信號被發射,當鼠標按鈕被按下。鼠標按下項的指定是通過 index 。信號纔發射,當索引有效時。

使用 QApplication::mouseButtons () 函數以獲取鼠標按鈕狀態。

另請參閱 activated (), clicked (), doubleClicked (),和 entered ().

[virtual slot] void QAbstractItemView:: reset ()

重置視圖的內部狀態。

警告: 此函數將重置已打開的編輯器、滾動條位置、選定、等。現有變化不會被提交。若想要在重置視圖時保存更改,可以重實現此函數,提交改變,然後調用超類實現。

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

重實現自 QWidget::resizeEvent ().

此函數被調用采用給定 event 當重置大小事件被發送給 Widget 時。

另請參閱 QWidget::resizeEvent ().

QModelIndex QAbstractItemView:: rootIndex () const

返迴模型根項的模型索引。根項是視圖頂層項的父級項。根可以無效。

另請參閱 setRootIndex ().

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

此槽被調用,當行即將被移除時。被刪除行是那些在給定 parent from start to end 包括在內。

另請參閱 rowsInserted ().

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

此槽被調用,當行被插入時。新行是那些在給定 parent from start to end (包括在內)。基類實現調用模型 fetchMore() 以校驗是否有更多數據。

另請參閱 rowsAboutToBeRemoved ().

[protected] void QAbstractItemView:: scheduleDelayedItemsLayout ()

調度要執行的視圖項布局,當事件處理開始時。

即使在事件處理前多次調用 scheduleDelayedItemsLayout(),視圖也隻做一次布局。

另請參閱 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 ()

選擇視圖中的所有項。這個函數將使用視圖設置的選定行為,當選擇時。

另請參閱 setSelection (), selectedIndexes (),和 clearSelection ().

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

此方便函數返迴視圖中所有選中和非隱藏項的索引列錶。列錶不包含重復項,且不排序。

另請參閱 QItemSelectionModel::selectedIndexes ().

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

此槽被調用,當選定改變時。先前選定 (可能為空) 的指定是通過 deselected ,和新選定通過 selected .

另請參閱 setSelection ().

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

返迴要使用的 SelectionFlags 當更新選定項包括 index 指定。 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 對於項在給定 index ,將 Widget 的所有權傳遞給視口。

index 無效 (如:若傳遞根索引),此函數什麼都不做。

給定 widget 's autoFillBackground 特性必須被設為 true,否則 Widget 背景將是透明的,展示模型數據和項兩者在給定 index .

若以索引小部件 B 替換索引小部件 A,將刪除索引小部件 A。例如,在以下代碼片段中, QLineEdit 對象將被刪除。

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

此函數隻應用於在數據項相應可見區域內顯示靜態內容。若想要顯示自定義動態內容 (或實現自定義編輯器 Widget),子類 QItemDelegate 代替。

該函數在 Qt 4.1 引入。

另請參閱 indexWidget () 和 委托類 .

void QAbstractItemView:: setItemDelegate ( QAbstractItemDelegate * delegate )

將此視圖及其模型的項委托設為 delegate 。若想要完整控製項的編輯和顯示,這就很有用。

任何現有委托將被移除,但不被刪除。 QAbstractItemView 未擁有所有權對於 delegate .

警告: 不應該在視圖之間,共享實例化的相同委托。這樣做會導緻不正確 (或不直觀) 編輯行為,由於連接到給定委托的各視圖都可以接收 closeEditor() 信號,且試圖訪問、修改或關閉已關閉的編輯器。

另請參閱 itemDelegate ().

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

設置給定項 delegate 用於此視圖和模型為給定 column 。所有項對於 column 的繪製和管理將是通過 delegate 而不是使用默認委托 (即 itemDelegate ()).

任何現有列委托對於 column 會被移除,但不刪除。 QAbstractItemView 未擁有所有權對於 delegate .

注意: 若委托已賦值給行和列兩者,行委托優先且它會管理相交單元格索引。

警告: 不應該在視圖之間,共享實例化的相同委托。這樣做會導緻不正確 (或不直觀) 編輯行為,由於連接到給定委托的各視圖都可以接收 closeEditor() 信號,且試圖訪問、修改或關閉已關閉的編輯器。

該函數在 Qt 4.2 引入。

另請參閱 itemDelegateForColumn (), setItemDelegateForRow (),和 itemDelegate ().

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

設置給定項 delegate 用於此視圖和模型為給定 row 。所有項對於 row 的繪製和管理將是通過 delegate 而不是使用默認委托 (即 itemDelegate ()).

任何現有行委托對於 row 會被移除,但不刪除。 QAbstractItemView 未擁有所有權對於 delegate .

注意: 若委托已賦值給行和列兩者,行委托 (即:此委托) 優先且它會管理相交單元格索引。

警告: 不應該在視圖之間,共享實例化的相同委托。這樣做會導緻不正確 (或不直觀) 編輯行為,由於連接到給定委托的各視圖都可以接收 closeEditor() 信號,且試圖訪問、修改或關閉已關閉的編輯器。

該函數在 Qt 4.2 引入。

另請參閱 itemDelegateForRow (), setItemDelegateForColumn (),和 itemDelegate ().

[虛擬] void QAbstractItemView:: setModel ( QAbstractItemModel * model )

設置 model 為要呈現視圖。

此函數將創建並設置新的選定模型,替換任何先前設置的模型采用 setSelectionModel ()。不管怎樣,舊選定模型不會被刪除,因為它可以在幾個視圖之間共享。推薦刪除舊選定模型,若不再需要。這的完成是采用以下代碼:

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

若舊模型和舊選定模型兩者沒有父級,或者若它們的父級是長期存活對象,可以首選調用它們的 deleteLater () 函數以明確刪除它們。

視圖 does not 擁有模型的所有權,除非它是模型的父級對象,因為模型可以在很多不同視圖之間共享。

另請參閱 model (), selectionModel (),和 setSelectionModel ().

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

將根項設為項按給定 index .

另請參閱 rootIndex ().

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

應用選定 flags 到矩形內項,或觸及的通過矩形 rect .

當實現自己的項視圖時,setSelection 應調用 selectionModel ()->select(selection, flags) 其中 selection 為空 QModelIndex QItemSelection 其包含的所有項包含在 rect .

另請參閱 selectionCommand () 和 selectedIndexes ().

[虛擬] void QAbstractItemView:: setSelectionModel ( QItemSelectionModel * selectionModel )

將當前選定模型設為給定 selectionModel .

注意,若調用 setModel () 在此函數後,給定 selectionModel 將被視圖創建的所替換。

注意: 直到應用程序刪除它,若不再需要舊選定模型 (即:若它未用於其它視圖)。這會自動發生,當刪除其父級對象時。不管怎樣,若它沒有父級對象 (或父級是長期存活對象),首選調用其 deleteLater () 函數以明確刪除它。

另請參閱 selectionModel (), setModel (),和 clearSelection ().

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

將項視圖的狀態設為給定 state .

另請參閱 state ().

[虛擬] int QAbstractItemView:: sizeHintForColumn ( int column ) const

返迴寬度大小提示為指定 column 或 -1 若沒有模型。

此函數用於具有水平 Header (頭) 的視圖,以查找 Header (頭) 區間的大小提示基於內容為給定 column .

另請參閱 sizeHintForRow ().

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

返迴大小提示為項采用指定 index 或無效大小對於無效索引。

另請參閱 sizeHintForRow () 和 sizeHintForColumn ().

[虛擬] int QAbstractItemView:: sizeHintForRow ( int row ) const

返迴高度大小提示為指定 row 或 -1 若沒有模型。

返迴使用大小提示計算的高度為給定 row 的項 (即:返迴值是項之間的最大高度)。注意,要控製行高度,必須重實現 QAbstractItemDelegate::sizeHint () 函數。

此函數用於具有垂直 Header (頭) 的視圖,基於內容查找 Header (頭) 區間的大小提示對於給定 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 )

更新占用區域通過給定 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 結構將填充視圖的調色闆、字體、狀態、對齊等。

[signal] void QAbstractItemView:: viewportEntered ()

此信號被發射,當鼠標光標進入視口時。鼠標追蹤需要啓用為使此特徵能工作。

另請參閱 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 ().