QAbstractItemView类参考

68 篇文章 24 订阅

QAbstractItemView类参考

QAbstractItemView类提供项目视图类的基本功能。更多

 #include< QAbstractItemView >

qmake: QT   +=   widgets

继承自:QAbstractScrollArea

被继承:QColumnViewQHeaderViewQListView,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 = 0)
  ~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)
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

公共槽

信号

受保护的类型


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::KeyboardModifiersmodifiers) = 0
void scheduleDelayedItemsLayout()
void scrollDirtyRegion(int dx, int dy)
virtual QModelIndexList selectedIndexes() const
virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex & index, const QEvent * event = 0) const
void setDirtyRegion(const QRegion & region)
virtual void setSelection(const QRect & rect, QItemSelectionModel::SelectionFlagsflags) = 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()

  • 1个保护槽继承自QWidget
额外的继承成员
  • 1 个公有变量继承自 QObject
  • 5 个公有的静态成员继承自 QWidget
  • 10 个公有的静态成员继承自 QObject
  • 2 个受保护的变量继承自 QObject
  • 1 个受保护的类型继承自 QPaintDevice

详细说明

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

QAbstractItemView类是一个基类,它为每个标准视图,使用QAbstractItemModel。QAbstractItemView是一个抽象类并且本身不能被实例化。它和模型通过信号和槽机制为互操作提供了一个标准接口,使子类来保持最新的与他们的模型的变化。该类提供了键盘和鼠标导航,视图滚动,编辑项目和选择的标准支持。实现这项功能的键盘导航:

钥匙 功能
箭头键 改变当前的项目和选择。
按Ctrl +箭头键 改变现行的项目而不选择它。
Shift +箭头键 改变当前的项目和选择。以前选择的项目(S)不取消。
CTR +空格 当前项目的切换选择。
Tab/Backtab 更改当前项目下/上一个项目。
Home/End 选择模型中的第一/最后的项目。
Page up/Page down 向上/下滚动视图中的可见行
Ctrl + A 选择模型中的所有项目。

注意:上表假设选择模式允许的操作。例如,如果选择模式为QAbstractItemView::NoSelection,你不能选择项目。

QAbstractItemView类是模型/视图类模型/视图架构的一部分

视图类继承QAbstractItemView只需要实现他们自己的视图—指定的功能,如绘制项,返回项的几何形状,查找项等。

QAbstractItemView提供常见的槽如edit()和setcurrentindex()。还提供了许多保护槽,包括dataChanged(),rowsInserted(),rowsAboutToBeRemoved(),selectionChanged()和 currentChanged()。

rootIndex()返回根项,当前项currentIndex()。确保一个项是可见的使用scrollTo()。

QAbstractItemView的一些函数和滚动有关,例如setHorizontalScrollMode()和setVerticalScrollMode()。要设置滚动条的范围,你可以重新实现视图的resizeEvent()函数:

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

注意范围直到控件显示时才会被更新。

几个和选择控制相关的函数:例如setSelectionMode(),setSelectionBehavior().这个类提供了一个默认的选择模式(selectionModel()),但这可以通过使用一个QItemSelectionModel实例调用setSelectionModel()被替换。

为了完全控制项的显示和编辑,你可以用setItemDelegate()指定一个代理。

QAbstractItemView提供了大量的保护函数。一些和编辑有关的函数如edit(),commitData().而其他的是键盘和鼠标的事件处理。

注意:如果你继承QAbstractItemView并打算更新视口的内容,你应该用viewport->update()而不是让所有的绘制操作发生在视口的update()。

也可查看 View ClassesModel/View ProgrammingQAbstractItemModel, and Chart Example.

如果旧的模式和旧的选择模型没有父母,或如果他们的父母长寿的对象,它可能是最好打电话给他们deletelater()函数来删除它。

视图除非它的父对象的模型,因为模型可能有许多不同的视图之间共享将模型的所有权。

参见模型(),选择模式(),和setselectionmodel()。

成员类型文档

enum QAbstractItemView::CursorAction

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

Constant Value Description
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)。

Constant Value Description
QAbstractItemView::NoDragDrop 0 不支持拖放
QAbstractItemView::DragOnly 1 仅支持视图项的拖动
QAbstractItemView::DropOnly 2 接受放下(drop)
QAbstractItemView::DragDrop 3 视图支持拖放
QAbstractItemView::InternalMove 4 视图仅支持来自自身的移动操作(不复制)
请注意,使用的模型需要提供拖放操作的支持。

这个枚举类型在Qt4.2被引进或修改。

参见setDragDropMode()和在项视图中使用拖放。

enum QAbstractItemView::DropIndicatorPosition

这个枚举类型标明了和当前鼠标位置相关的索引的按下位置

Constant Value Description
QAbstractItemView::OnItem 0 The item will be dropped on the index.
QAbstractItemView::AboveItem 1 The item will be dropped above the index.
QAbstractItemView::BelowItem 2 The item will be dropped below the index.
QAbstractItemView::OnViewport 3 The item will be dropped onto a region of the viewport with no items. The way each view handles items dropped onto the viewport depends on the behavior of the underlying model in use.

enum QAbstractItemview::EditTrigger


flags QAbstractItemView::EditTriggers

此枚举描述了将要开始的项编辑的动作。

Constant Value Description
QAbstractItemView::NoEditTriggers 0 No editing possible.
QAbstractItemView::CurrentChanged 1 只要当前项改变,编辑开始
QAbstractItemView::DoubleClicked 2 当一个项被双击时编辑开始
QAbstractItemView::SelectedClicked 4 在已选择项上单击时编辑开始
QAbstractItemView::EditKeyPressed 8 在项上当编辑键被按下时编辑开始
QAbstractItemView::AnyKeyPressed 16 在项上任何键被按下编辑开始
QAbstractItemView::AllEditTriggers 31 上述所有触发编辑开始
EditTriggers类型是QFlags<EditTrigger>的typedef,它存储了EditTrigger值的一个或操作。

enum QAbstractItemView::ScrollHint

Constant Value Description
QAbstractItemView::EnsureVisible 0 滚动以确保项可见
QAbstractItemView::PositionAtTop 1 滚动到视口顶部项的位置
QAbstractItemView::PositionAtBottom 2 滚动到视口底部项的位置
QAbstractItemView::PositionAtCenter 3 滚动到视口中心项的位置

enum QAbstractItemView::ScrollMode

Constant Value Description
QAbstractItemView::ScrollPerItem 0 视图将滚动内容一次一项
QAbstractItemView::ScrollPerPixel 1 视图将滚动内容一次一像素
这个枚举在Qt4.2被引进或修改。

enum QAbstractItemView::SelectionBehavior

Constant Value Description
QAbstractItemView::SelectItems 0 选择项
QAbstractItemView::SelectRows 1 仅选择行
QAbstractItemView::SelectColumns 2 仅选择列

enum QAbstractItemView::SelectionMode

This enum indicates how the view responds to user selections:

Constant Value Description
QAbstractItemView::SingleSelection 1 当用户选择一个项目时,任何已选定的项目成为未选中状态,并且用户不能通过单击已选择的项来取消选择。
QAbstractItemView::ContiguousSelection 4 When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item.按下Shift可多选或取消选择
QAbstractItemView::ExtendedSelection 3 When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Ctrl key when clicking on an item, the clicked item gets toggled and all other items are left untouched. If the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item. Multiple items can be selected by dragging the mouse over them.按下Ctrl可多选或取消选择
QAbstractItemView::MultiSelection 2 When the user selects an item in the usual way, the selection status of that item is toggled and the other items are left alone. Multiple items can be toggled by dragging the mouse over them.可拖动多选
QAbstractItemView::NoSelection 0 项不能被选择

最常用的方式是singleselection和extendedselection。

enum QAbstractItemView::State

描述了视图可处于的不同状态。 当重写你自己的视图时这通常是有趣的。

Constant Value Description
QAbstractItemView::NoState 0 默认
QAbstractItemView::DraggingState 1 用户正在拖动项
QAbstractItemView::DragSelectingState 2 用户正在选择项
QAbstractItemView::EditingState 3 用户在一个可编辑控件中编辑项
QAbstractItemView::ExpandingState 4 用户正打开一个项的分支
QAbstractItemView::CollapsingState 5 用户正关闭一个项的分支
QAbstractItemView::AnimatingState 6 项视图正在进行动画

属性文档

alternatingRowColorsbool

这个属性保存的是是否用可交替颜色去绘制背景。

如果此属性为真,项目背景将使用QPalette::baseQPalette::AlternateBase绘制;否则将用QPalette::Base绘制背景。

默认情况下,此属性为false

访问函数:

bool alternatingRowColors() const
void setAlternatingRowColors(bool enable)

autoScroll : bool

这个属性判断当拖动移动事件可用时是否自动滚动。

如果此属性设置为True(默认的),QAbstractItemView自动滚动视图的内容,当用户在视口边缘的16像素内拖动时。如果当前项目改变了,视图将自动滚动以确保当前项完全可见。

此属性仅在视口接受drop时可用。设置为false关闭此属性。

访问功能:

Access functions:

bool hasAutoScroll() const
void setAutoScroll(bool enable)

autoScrollMargin : int

这个属性保存的是面积的大小,当自动滚动触发。

此属性可以控制面积的大小在边缘的视图,触发器autoscrolling。默认值是16像素。

此属性进行了Qt 4.4。

访问函数:

bool hasAutoScroll() const
void setAutoScroll(bool enable)

autoScrollMargin : int

此属性持有当自动滚动被触发时的区域的大小。

此属性控制了触发自动滚动时视口边缘区域的尺寸。默认值是16像素。

此属性在Qt4.4被引进。

访问函数:

int autoScrollMargin() const
void setAutoScrollMargin(int margin)

defaultDropAction : Qt::DropAction

这个属性持有将在QAbstractItemView::drag()中被用到的默认(鼠标拖动)松开动作。

如果此属性没被设置,松开动作是CopyAction,如果可支持的动作支持CopyAction的话。

此属性在Qt4.6被引进。

访问函数:

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

也可查看 showDropIndicator 和 dragDropOverwriteMode.

dragDropMode : DragDropMode

这个属性保存视图将采用的拖放事件。

此属性被引进始自Qt 4.2。

访问函数:

DragDropMode dragDropMode() const
void setDragDropMode(DragDropMode behavior)

也可查看 showDropIndicator 和 dragDropOverwriteMode.

dragDropOverwriteMode : bool

这个属性保存的视图的拖放行为。

如果它的值是真的,当drop时选择的数据将覆盖现有的项目数据,而移动数据将会清除项目。如果它的值是false,当数据被drop时选定的数据将作为一个新的项被插入。当数据被移动,该项目也被除去。

QListViewQTreeView子类中默认设置为false。然而在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)

也可查看 showDropIndicatorDragDropModedragDropOverwriteMode, and acceptDrops.

editTriggers : EditTriggers

这个属性保存哪一个动作将启动项编辑。

此属性是一个被EditTrigger定义的标志选择,结合or操作。视图仅在动作在此属性中设置了的时候启动一个项的编辑

可使用函数:

EditTriggers editTriggers() const
void setEditTriggers(EditTriggers triggers)

horizontalScrollMode : ScrollMode

这个属性保存的是视图如何在水平方向上滚动内容。

此属性可以控制视图如何水平滚动其内容。滚动可以每像素或每项。

此属性始自Qt 4.2。

访问函数:

ScrollMode horizontalScrollMode() const
void setHorizontalScrollMode(ScrollMode mode)

iconSize : QSize

这个属性保存项图标的大小。

视图可见时设置此属性将造成项再次被布局。

访问函数:

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

selectionBehavior : SelectionBehavior

这个属性保存视图使用的选择行为。

这个属性保存的是选择行为:单一项目,行或列。

访问函数:

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

也可查看 SelectionMode 和 SelectionBehavior.

selectionMode : SelectionMode

这个属性保存视图中的选择模式。

This property controls whether the user can select one or many items and, in many-item selections, whether the selection must be a continuous range of items.

Access functions:

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

See also SelectionMode and SelectionBehavior.

showDropIndicator : bool

This property holds whether the drop indicator is shown when dragging items and dropping.

Access functions:

bool showDropIndicator() const
void setDropIndicatorShown(bool enable)

See also dragEnabledDragDropModedragDropOverwriteMode, and acceptDrops.

tabKeyNavigation : bool

This property holds whether item navigation with tab and backtab is enabled.

Access functions:

bool tabKeyNavigation() const
void setTabKeyNavigation(bool enable)

textElideMode : Qt::TextElideMode

This property holds the position of the "..." in elided text.

The default value for all item views is Qt::ElideRight.

Access functions:

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

verticalScrollMode : ScrollMode

This property holds how the view scrolls its contents in the vertical direction.

This property controls how the view scroll its contents vertically. Scrolling can be done either per pixel or per item.

This property was introduced in Qt 4.2.

Access functions:

ScrollMode verticalScrollMode() const
void setVerticalScrollMode(ScrollMode mode)

Member Function Documentation

QAbstractItemView::QAbstractItemView(QWidget * parent = 0)

Constructs an abstract item view with the given parent.

QAbstractItemView::~QAbstractItemView()

Destroys the view.

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

This signal is emitted when the item specified by 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.

See also clicked(), doubleClicked(), entered(), and pressed().

void QAbstractItemView::clearSelection() [slot]

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

See also setSelection() and selectAll().

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

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.

See also activated(), doubleClicked(), entered(), and pressed().

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

Closes the given 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.

See also edit() and commitData().

void QAbstractItemView::closePersistentEditor(const QModelIndex & index)

Closes the persistent editor for the item at the given index.

See also openPersistentEditor().

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

Commit the data in the editor to the model.

See also closeEditor().

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

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

QModelIndex QAbstractItemView::currentIndex() const

Returns the model index of the current item.

See also setCurrentIndex().

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

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.

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

QPoint QAbstractItemView::dirtyRegionOffset() const [protected]

Returns the offset of the dirty regions in the view.

If you use scrollDirtyRegion() and implement a paintEvent() in a subclass of QAbstractItemView, you should translate the area given by the paint event with the offset returned from this function.

See also scrollDirtyRegion() and setDirtyRegion().

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

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.

See also clicked() and activated().

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

Reimplemented from QWidget::dragEnterEvent().

This function is called with the given 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.

See also dropEvent() and startDrag().

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

Reimplemented from 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.

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

Reimplemented from 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.

See also dropEvent() and startDrag().

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

Reimplemented from QWidget::dropEvent().

This function is called with the given event when a drop event occurs over the widget. If the model accepts the even position the drop event is accepted; otherwise it is ignored.

See also startDrag().

DropIndicatorPosition QAbstractItemView::dropIndicatorPosition() const[protected]

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

This function was introduced in Qt 4.1.

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

Starts editing the item corresponding to the given index if it is editable.

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() before this function with the same model index.

See also QModelIndex::flags().

bool QAbstractItemView::edit(const QModelIndex & indexEditTriggertriggerQEvent * event) [virtual protected]

Starts editing the item at index, creating an editor if necessary, and returns true if the view'sState is now EditingState; otherwise returns 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 to be QAbstractItemView::AllEditTriggers.

See also closeEditor().

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

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

See also closeEditor().

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

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.

See also viewportEntered(), activated(), clicked(), doubleClicked(), and pressed().

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

Reimplemented from QObject::event().

void QAbstractItemView::executeDelayedItemsLayout() [protected]

Executes the scheduled layouts without waiting for the event processing to begin.

See also scheduleDelayedItemsLayout().

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

Reimplemented from QWidget::focusInEvent().

This function is called with the given event when the widget obtains the focus. By default, the event is ignored.

See also setFocus() and focusOutEvent().

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

Reimplemented from QWidget::focusNextPrevChild().

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

Reimplemented from QWidget::focusOutEvent().

This function is called with the given event when the widget looses the focus. By default, the event is ignored.

See also clearFocus() and focusInEvent().

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

Returns the horizontal offset of the view.

In the base class this is a pure virtual function.

See also verticalOffset().

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

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

In the base class this is a pure virtual function.

See also visualRect().

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

Returns the widget for the item at the given index.

This function was introduced in Qt 4.1.

See also setIndexWidget().

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

Reimplemented from QWidget::inputMethodEvent().

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

Reimplemented from QWidget::inputMethodQuery().

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

Returns true if the item referred to by the given index is hidden in the view, otherwise returnsfalse.

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

In the base class this is a pure virtual function.

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.

See also 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(intcolumn) const

Returns the item delegate used by this view and model for the given column. You can callitemDelegate() to get a pointer to the current delegate for a given index.

This function was introduced in Qt 4.2.

See also setItemDelegateForColumn(), itemDelegateForRow(), and 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.

This function was introduced in Qt 4.2.

See also setItemDelegateForRow(), itemDelegateForColumn(), and setItemDelegate().

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

Reimplemented from QWidget::keyPressEvent().

This function is called with the given 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.

See also edit(), moveCursor(), keyboardSearch(), and tabKeyNavigation.

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

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.

See also setModel().

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

Reimplemented from QWidget::mouseDoubleClickEvent().

This function is called with the given 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.

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

Reimplemented from QWidget::mouseMoveEvent().

This function is called with the given 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.

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

Reimplemented from QWidget::mousePressEvent().

This function is called with the given 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() signal.

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

Reimplemented from QWidget::mouseReleaseEvent().

This function is called with the given 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.

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

Returns a QModelIndex object pointing to the next object in the view, based on the given cursorActionand keyboard modifiers specified by modifiers.

In the base class this is a pure virtual function.

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.

See also closePersistentEditor().

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

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.

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

See also activated(), clicked(), doubleClicked(), and entered().

void QAbstractItemView::reset() [virtual slot]

Reset the internal state of the view.

Warning: 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.

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

Reimplemented from QWidget::resizeEvent().

This function is called with the given event when a resize event is sent to the widget.

See also 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.

See also setRootIndex().

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

This slot is called when rows are about to be removed. The deleted rows are those under the givenparent from start to end inclusive.

See also rowsInserted().

void QAbstractItemView::rowsInserted(const QModelIndex & parentintstartint end) [virtual protected slot]

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

See also rowsAboutToBeRemoved().

void QAbstractItemView::scheduleDelayedItemsLayout() [protected]

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.

See also executeDelayedItemsLayout().

void QAbstractItemView::scrollDirtyRegion(int dxint dy) [protected]

Prepares the view for scrolling by (dx,dy) pixels by moving the dirty regions in the opposite direction. You only need to call this function if you are implementing a scrolling viewport in your view subclass.

If you implement scrollContentsBy() in a subclass of QAbstractItemView, call this function before you call QWidget::scroll() on the viewport. Alternatively, just call update().

See also scrollContentsBy(), dirtyRegionOffset(), and setDirtyRegion().

void QAbstractItemView::scrollTo(const QModelIndex & indexScrollHinthint = EnsureVisible) [pure virtual]

Scrolls the view if necessary to ensure that the item at index is visible. The view will try to position the item according to the given hint.

In the base class this is a pure virtual function.

void QAbstractItemView::scrollToBottom() [slot]

Scrolls the view to the bottom.

This function was introduced in Qt 4.1.

See also scrollTo() and scrollToTop().

void QAbstractItemView::scrollToTop() [slot]

Scrolls the view to the top.

This function was introduced in Qt 4.1.

See also scrollTo() and scrollToBottom().

void QAbstractItemView::selectAll() [virtual slot]

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

See also setSelection(), selectedIndexes(), and clearSelection().

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

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.

See also QItemSelectionModel::selectedIndexes().

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

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.

See also setSelection().

QItemSelectionModel::SelectionFlagsQAbstractItemView::selectionCommand(const QModelIndex & index, const QEvent* event = 0) const [virtual protected]

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.

Reimplement this function to define your own selection behavior.

See also setSelection().

QItemSelectionModel * QAbstractItemView::selectionModel() const

Returns the current selection model.

See also setSelectionModel() and selectedIndexes().

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

Sets the current item to be the item at index.

Unless the current selection mode is NoSelection, the item is also selected. Note that this function also updates the starting position for any new selections the user performs.

To set an item as the current item without selecting it, call

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

See also currentIndex(), currentChanged(), and selectionMode.

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

Marks the given region as dirty and schedules it to be updated. You only need to call this function if you are implementing your own view subclass.

This function was introduced in Qt 4.1.

See also scrollDirtyRegion() and dirtyRegionOffset().

void QAbstractItemView::setIndexWidget(const QModelIndex & indexQWidget* widget)

Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.

If index is invalid (e.g., if you pass the root index), this function will do nothing.

The given 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 instead.

This function was introduced in Qt 4.1.

See also indexWidget() and Delegate Classes.

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.

Any existing delegate will be removed, but not deleted. QAbstractItemView does not take ownership ofdelegate.

Warning: 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() signal, and attempt to access, modify or close an editor that has already been closed.

See also 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 columnwill 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 does not take ownership of delegate.

Note: 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.

Warning: 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() signal, and attempt to access, modify or close an editor that has already been closed.

This function was introduced in Qt 4.2.

See also itemDelegateForColumn(), setItemDelegateForRow(), and 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 does not take ownership of delegate.

Note: 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.

Warning: 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() signal, and attempt to access, modify or close an editor that has already been closed.

This function was introduced in Qt 4.2.

See also itemDelegateForRow(), setItemDelegateForColumn(), and itemDelegate().

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

Sets the 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.

See also model(), selectionModel(), and setSelectionModel().

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

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

See also rootIndex().

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

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 or a QItemSelection that contains all items that are contained in rect.

See also selectionCommand() and selectedIndexes().

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

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.

Note: 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.

See also selectionModel(), setModel(), and clearSelection().

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

Sets the item view's state to the given state.

See also state().

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

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

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

See also sizeHintForRow().

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

Returns the size hint for the item with the specified index or an invalid size for invalid indexes.

See also sizeHintForRow() and sizeHintForColumn().

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

Returns the height size hint for the specified row or -1 if there is no model.

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

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.

See also sizeHintForColumn().

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

Starts a drag by calling drag->exec() using the given supportedActions.

State QAbstractItemView::state() const [protected]

Returns the item view's state.

See also setState().

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

Reimplemented from QObject::timerEvent().

This function is called with the given event when a timer event is sent to the widget.

See also QObject::timerEvent().

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

Updates the area occupied by the given index.

This function was introduced in Qt 4.3.

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

Updates the geometry of the child widgets of the view.

This function was introduced in Qt 4.4.

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

Returns the vertical offset of the view.

In the base class this is a pure virtual function.

See also horizontalOffset().

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

Returns a QStyleOptionViewItem structure populated with the view's palette, font, state, alignments etc.

void QAbstractItemView::viewportEntered() [signal]

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

See also entered().

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

Reimplemented from QAbstractScrollArea::viewportEvent().

This function is used to handle tool tips, and What's This? mode, if the given event is aQEvent::ToolTip,or a QEvent::WhatsThis. It passes all other events on to its base class viewportEvent() handler.

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

Reimplemented from QAbstractScrollArea::viewportSizeHint().

This function was introduced in Qt 5.2.

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

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

If your item is displayed in several areas then visualRect should return the primary area that contains index and not the complete area that index might encompasses, touch or cause drawing.

In the base class this is a pure virtual function.

See also indexAt() and visualRegionForSelection().

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

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

In the base class this is a pure virtual function.

See also visualRect() and selectedIndexes().




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值