Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QAbstractItemView Class

TheQAbstractItemView class provides the basic functionality for item view classes.More...

Header:#include <QAbstractItemView>
Inherits:QAbstractScrollArea
Inherited By:

QColumnView,QHeaderView,QListView,QTableView, andQTreeView

Public Types

enumDragDropMode { NoDragDrop, DragOnly, DropOnly, DragDrop, InternalMove }
enumEditTrigger { NoEditTriggers, CurrentChanged, DoubleClicked, SelectedClicked, ..., AllEditTriggers }
flagsEditTriggers
enumScrollHint { EnsureVisible, PositionAtTop, PositionAtBottom, PositionAtCenter }
enumScrollMode { ScrollPerItem, ScrollPerPixel }
enumSelectionBehavior { SelectItems, SelectRows, SelectColumns }
enumSelectionMode { SingleSelection, ContiguousSelection, ExtendedSelection, MultiSelection, NoSelection }

Properties

Public Functions

QAbstractItemView(QWidget * parent = 0)
~QAbstractItemView()
boolalternatingRowColors() const
intautoScrollMargin() const
voidclosePersistentEditor(const QModelIndex & index)
QModelIndexcurrentIndex() const
Qt::DropActiondefaultDropAction() const
DragDropModedragDropMode() const
booldragDropOverwriteMode() const
booldragEnabled() const
EditTriggerseditTriggers() const
boolhasAutoScroll() const
ScrollModehorizontalScrollMode() const
QSizeiconSize() const
virtual QModelIndexindexAt(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 voidkeyboardSearch(const QString & search)
QAbstractItemModel *model() const
voidopenPersistentEditor(const QModelIndex & index)
QModelIndexrootIndex() const
virtual voidscrollTo(const QModelIndex & index, ScrollHint hint = EnsureVisible) = 0
QAbstractItemView::SelectionBehaviorselectionBehavior() const
QAbstractItemView::SelectionModeselectionMode() const
QItemSelectionModel *selectionModel() const
voidsetAlternatingRowColors(bool enable)
voidsetAutoScroll(bool enable)
voidsetAutoScrollMargin(int margin)
voidsetDefaultDropAction(Qt::DropAction dropAction)
voidsetDragDropMode(DragDropMode behavior)
voidsetDragDropOverwriteMode(bool overwrite)
voidsetDragEnabled(bool enable)
voidsetDropIndicatorShown(bool enable)
voidsetEditTriggers(EditTriggers triggers)
voidsetHorizontalScrollMode(ScrollMode mode)
voidsetIconSize(const QSize & size)
voidsetIndexWidget(const QModelIndex & index, QWidget * widget)
voidsetItemDelegate(QAbstractItemDelegate * delegate)
voidsetItemDelegateForColumn(int column, QAbstractItemDelegate * delegate)
voidsetItemDelegateForRow(int row, QAbstractItemDelegate * delegate)
virtual voidsetModel(QAbstractItemModel * model)
voidsetSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
voidsetSelectionMode(QAbstractItemView::SelectionMode mode)
virtual voidsetSelectionModel(QItemSelectionModel * selectionModel)
voidsetTabKeyNavigation(bool enable)
voidsetTextElideMode(Qt::TextElideMode mode)
voidsetVerticalScrollMode(ScrollMode mode)
boolshowDropIndicator() const
virtual intsizeHintForColumn(int column) const
QSizesizeHintForIndex(const QModelIndex & index) const
virtual intsizeHintForRow(int row) const
booltabKeyNavigation() const
Qt::TextElideModetextElideMode() const
ScrollModeverticalScrollMode() const
virtual QRectvisualRect(const QModelIndex & index) const = 0

Reimplemented Public Functions

virtual QVariantinputMethodQuery(Qt::InputMethodQuery query) const

Public Slots

voidclearSelection()
voidedit(const QModelIndex & index)
virtual voidreset()
voidscrollToBottom()
voidscrollToTop()
virtual voidselectAll()
voidsetCurrentIndex(const QModelIndex & index)
virtual voidsetRootIndex(const QModelIndex & index)
voidupdate(const QModelIndex & index)
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidactivated(const QModelIndex & index)
voidclicked(const QModelIndex & index)
voiddoubleClicked(const QModelIndex & index)
voidentered(const QModelIndex & index)
voidpressed(const QModelIndex & index)
voidviewportEntered()

Protected Types

enumCursorAction { MoveUp, MoveDown, MoveLeft, MoveRight, ..., MovePrevious }
enumDropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport }
enumState { NoState, DraggingState, DragSelectingState, EditingState, ..., AnimatingState }

Protected Functions

QPointdirtyRegionOffset() const
DropIndicatorPositiondropIndicatorPosition() const
virtual booledit(const QModelIndex & index, EditTrigger trigger, QEvent * event)
voidexecuteDelayedItemsLayout()
virtual inthorizontalOffset() const = 0
virtual boolisIndexHidden(const QModelIndex & index) const = 0
virtual QModelIndexmoveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) = 0
voidscheduleDelayedItemsLayout()
voidscrollDirtyRegion(int dx, int dy)
virtual QModelIndexListselectedIndexes() const
virtual QItemSelectionModel::SelectionFlagsselectionCommand(const QModelIndex & index, const QEvent * event = 0) const
voidsetDirtyRegion(const QRegion & region)
virtual voidsetSelection(const QRect & rect, QItemSelectionModel::SelectionFlags flags) = 0
voidsetState(State state)
virtual voidstartDrag(Qt::DropActions supportedActions)
Statestate() const
virtual intverticalOffset() const = 0
virtual QStyleOptionViewItemviewOptions() const
virtual QRegionvisualRegionForSelection(const QItemSelection & selection) const = 0

Reimplemented Protected Functions

virtual voiddragEnterEvent(QDragEnterEvent * event)
virtual voiddragLeaveEvent(QDragLeaveEvent * event)
virtual voiddragMoveEvent(QDragMoveEvent * event)
virtual voiddropEvent(QDropEvent * event)
virtual boolevent(QEvent * event)
virtual voidfocusInEvent(QFocusEvent * event)
virtual boolfocusNextPrevChild(bool next)
virtual voidfocusOutEvent(QFocusEvent * event)
virtual voidinputMethodEvent(QInputMethodEvent * event)
virtual voidkeyPressEvent(QKeyEvent * event)
virtual voidmouseDoubleClickEvent(QMouseEvent * event)
virtual voidmouseMoveEvent(QMouseEvent * event)
virtual voidmousePressEvent(QMouseEvent * event)
virtual voidmouseReleaseEvent(QMouseEvent * event)
virtual voidresizeEvent(QResizeEvent * event)
virtual voidtimerEvent(QTimerEvent * event)
virtual boolviewportEvent(QEvent * event)

Protected Slots

virtual voidcloseEditor(QWidget * editor, QAbstractItemDelegate::EndEditHint hint)
virtual voidcommitData(QWidget * editor)
virtual voidcurrentChanged(const QModelIndex & current, const QModelIndex & previous)
virtual voiddataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight)
virtual voideditorDestroyed(QObject * editor)
virtual voidrowsAboutToBeRemoved(const QModelIndex & parent, int start, int end)
virtual voidrowsInserted(const QModelIndex & parent, int start, int end)
virtual voidselectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
virtual voidupdateGeometries()

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject

Detailed Description

TheQAbstractItemView class provides the basic functionality for item view classes.

QAbstractItemView class is the base class for every standard view that uses aQAbstractItemModel.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:

KeysFunctionality
Arrow keysChanges the current item and selects it.
Ctrl+Arrow keysChanges the current item but does not select it.
Shift+Arrow keysChanges the current item and selects it. The previously selected item(s) is not deselected.
Ctr+SpaceToggles selection of the current item.
Tab/BacktabChanges the current item to the next/previous item.
Home/EndSelects the first/last item in the model.
Page up/Page downScrolls the rows shown up/down by the number of visible rows in the view.
Ctrl+ASelects all items in the model.

Note that the above table assumes that theselection mode allows the operations. For instance, you cannot select items if the selection mode isQAbstractItemView::NoSelection.

TheQAbstractItemView class is one of theModel/View Classes and is part of Qt'smodel/view framework.

The view classes that inheritQAbstractItemView 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 asedit() andsetCurrentIndex(). Many protected slots are also provided, includingdataChanged(),rowsInserted(),rowsAboutToBeRemoved(),selectionChanged(), andcurrentChanged().

The root item is returned byrootIndex(), and the current item bycurrentIndex(). To make sure that an item is visible usescrollTo().

Some ofQAbstractItemView's functions are concerned with scrolling, for examplesetHorizontalScrollMode() andsetVerticalScrollMode(). To set the range of the scroll bars, you can, for example, reimplement the view'sresizeEvent() function:

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

Note that the range is not updated until the widget is shown.

Several other functions are concerned with selection control; for examplesetSelectionMode(), andsetSelectionBehavior(). This class provides a default selection model to work with (selectionModel()), but this can be replaced by usingsetSelectionModel() with an instance ofQItemSelectionModel.

For complete control over the display and editing of items you can specify a delegate withsetItemDelegate().

QAbstractItemView provides a lot of protected functions. Some are concerned with editing, for example,edit(), andcommitData(), whilst others are keyboard and mouse event handlers.

Note:If you inheritQAbstractItemView and intend to update the contents of the viewport, you should use viewport->update() instead ofupdate() as all painting operations take place on the viewport.

See alsoView Classes,Model/View Programming,QAbstractItemModel, andChart Example.

Member Type Documentation

enum QAbstractItemView::CursorAction

This enum describes the different ways to navigate between items,

ConstantValueDescription
QAbstractItemView::MoveUp0Move to the item above the current item.
QAbstractItemView::MoveDown1Move to the item below the current item.
QAbstractItemView::MoveLeft2Move to the item left of the current item.
QAbstractItemView::MoveRight3Move to the item right of the current item.
QAbstractItemView::MoveHome4Move to the top-left corner item.
QAbstractItemView::MoveEnd5Move to the bottom-right corner item.
QAbstractItemView::MovePageUp6Move one page up above the current item.
QAbstractItemView::MovePageDown7Move one page down below the current item.
QAbstractItemView::MoveNext8Move to the item after the current item.
QAbstractItemView::MovePrevious9Move to the item before the current item.

See alsomoveCursor().

enum QAbstractItemView::DragDropMode

Describes the various drag and drop events the view can act upon. By default the view does not support dragging or dropping (NoDragDrop).

ConstantValueDescription
QAbstractItemView::NoDragDrop0Does not support dragging or dropping.
QAbstractItemView::DragOnly1The view supports dragging of its own items
QAbstractItemView::DropOnly2The view accepts drops
QAbstractItemView::DragDrop3The view supports both dragging and dropping
QAbstractItemView::InternalMove4The view accepts move (not copy) operations only from itself.

Note that the model used needs to provide support for drag and drop operations.

This enum was introduced or modified in Qt 4.2.

See alsosetDragDropMode() andUsing drag and drop with item views.

enum QAbstractItemView::DropIndicatorPosition

This enum indicates the position of the drop indicator in relation to the index at the current mouse position:

ConstantValueDescription
QAbstractItemView::OnItem0The item will be dropped on the index.
QAbstractItemView::AboveItem1The item will be dropped above the index.
QAbstractItemView::BelowItem2The item will be dropped below the index.
QAbstractItemView::OnViewport3The 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

This enum describes actions which will initiate item editing.

ConstantValueDescription
QAbstractItemView::NoEditTriggers0No editing possible.
QAbstractItemView::CurrentChanged1Editing start whenever current item changes.
QAbstractItemView::DoubleClicked2Editing starts when an item is double clicked.
QAbstractItemView::SelectedClicked4Editing starts when clicking on an already selected item.
QAbstractItemView::EditKeyPressed8Editing starts when the platform edit key has been pressed over an item.
QAbstractItemView::AnyKeyPressed16Editing starts when any key is pressed over an item.
QAbstractItemView::AllEditTriggers31Editing starts for all above actions.

The EditTriggers type is a typedef forQFlags<EditTrigger>. It stores an OR combination of EditTrigger values.

enum QAbstractItemView::ScrollHint

ConstantValueDescription
QAbstractItemView::EnsureVisible0Scroll to ensure that the item is visible.
QAbstractItemView::PositionAtTop1Scroll to position the item at the top of the viewport.
QAbstractItemView::PositionAtBottom2Scroll to position the item at the bottom of the viewport.
QAbstractItemView::PositionAtCenter3Scroll to position the item at the center of the viewport.

enum QAbstractItemView::ScrollMode

ConstantValueDescription
QAbstractItemView::ScrollPerItem0The view will scroll the contents one item at a time.
QAbstractItemView::ScrollPerPixel1The view will scroll the contents one pixel at a time.

This enum was introduced or modified in Qt 4.2.

enum QAbstractItemView::SelectionBehavior

ConstantValueDescription
QAbstractItemView::SelectItems0Selecting single items.
QAbstractItemView::SelectRows1Selecting only rows.
QAbstractItemView::SelectColumns2Selecting only columns.

enum QAbstractItemView::SelectionMode

This enum indicates how the view responds to user selections:

ConstantValueDescription
QAbstractItemView::SingleSelection1When the user selects an item, any already-selected item becomes unselected, and the user cannot unselect the selected item by clicking on it.
QAbstractItemView::ContiguousSelection4When 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.
QAbstractItemView::ExtendedSelection3When 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.
QAbstractItemView::MultiSelection2When 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::NoSelection0Items cannot be selected.

The most commonly used modes are SingleSelection and ExtendedSelection.

enum QAbstractItemView::State

Describes the different states the view can be in. This is usually only interesting when reimplementing your own view.

ConstantValueDescription
QAbstractItemView::NoState0The is the default state.
QAbstractItemView::DraggingState1The user is dragging items.
QAbstractItemView::DragSelectingState2The user is selecting items.
QAbstractItemView::EditingState3The user is editing an item in a widget editor.
QAbstractItemView::ExpandingState4The user is opening a branch of items.
QAbstractItemView::CollapsingState5The user is closing a branch of items.
QAbstractItemView::AnimatingState6The item view is performing an animation.

Property Documentation

alternatingRowColors :bool

This property holds whether to draw the background using alternating colors.

If this property is true, the item background will be drawn usingQPalette::Base andQPalette::AlternateBase; otherwise the background will be drawn using theQPalette::Base color.

By default, this property is false.

Access functions:

boolalternatingRowColors() const
voidsetAlternatingRowColors(bool enable)

autoScroll :bool

This property holds whether autoscrolling in drag move events is enabled.

If this property is set to true (the default), theQAbstractItemView automatically scrolls the contents of the view if the user drags within 16 pixels of the viewport edge. If the current item changes, then the view will scroll automatically to ensure that the current item is fully visible.

This property only works if the viewport accepts drops. Autoscroll is switched off by setting this property to false.

Access functions:

boolhasAutoScroll() const
voidsetAutoScroll(bool enable)

autoScrollMargin :int

This property holds the size of the area when auto scrolling is triggered.

This property controls the size of the area at the edge of the viewport that triggers autoscrolling. The default value is 16 pixels.

This property was introduced in Qt 4.4.

Access functions:

intautoScrollMargin() const
voidsetAutoScrollMargin(int margin)

defaultDropAction :Qt::DropAction

This property holds the drop action that will be used by default in QAbstractItemView::drag().

If the property is not set, the drop action is CopyAction when the supported actions support CopyAction.

This property was introduced in Qt 4.6.

Access functions:

Qt::DropActiondefaultDropAction() const
voidsetDefaultDropAction(Qt::DropAction dropAction)

See alsoshowDropIndicator anddragDropOverwriteMode.

dragDropMode :DragDropMode

This property holds the drag and drop event the view will act upon.

This property was introduced in Qt 4.2.

Access functions:

DragDropModedragDropMode() const
voidsetDragDropMode(DragDropMode behavior)

See alsoshowDropIndicator anddragDropOverwriteMode.

dragDropOverwriteMode :bool

This property holds the view's drag and drop behavior.

If its value istrue, the selected data will overwrite the existing item data when dropped, while moving the data will clear the item. If its value isfalse, 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.

The default value isfalse, as in theQListView andQTreeView subclasses. In theQTableView subclass, on the other hand, the property has been set totrue.

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

This property was introduced in Qt 4.2.

Access functions:

booldragDropOverwriteMode() const
voidsetDragDropOverwriteMode(bool overwrite)

See alsodragDropMode.

dragEnabled :bool

This property holds whether the view supports dragging of its own items.

Access functions:

booldragEnabled() const
voidsetDragEnabled(bool enable)

See alsoshowDropIndicator,DragDropMode,dragDropOverwriteMode, andacceptDrops.

editTriggers :EditTriggers

This property holds which actions will initiate item editing.

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

Access functions:

EditTriggerseditTriggers() const
voidsetEditTriggers(EditTriggers triggers)

horizontalScrollMode :ScrollMode

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

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

This property was introduced in Qt 4.2.

Access functions:

ScrollModehorizontalScrollMode() const
voidsetHorizontalScrollMode(ScrollMode mode)

iconSize :QSize

This property holds the size of items' icons.

Setting this property when the view is visible will cause the items to be laid out again.

Access functions:

QSizeiconSize() const
voidsetIconSize(const QSize & size)

selectionBehavior :SelectionBehavior

This property holds which selection behavior the view uses.

This property holds whether selections are done in terms of single items, rows or columns.

Access functions:

QAbstractItemView::SelectionBehaviorselectionBehavior() const
voidsetSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)

See alsoSelectionMode andSelectionBehavior.

selectionMode :SelectionMode

This property holds which selection mode the view operates in.

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::SelectionModeselectionMode() const
voidsetSelectionMode(QAbstractItemView::SelectionMode mode)

See alsoSelectionMode andSelectionBehavior.

showDropIndicator :bool

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

Access functions:

boolshowDropIndicator() const
voidsetDropIndicatorShown(bool enable)

See alsodragEnabled,DragDropMode,dragDropOverwriteMode, andacceptDrops.

tabKeyNavigation :bool

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

Access functions:

booltabKeyNavigation() const
voidsetTabKeyNavigation(bool enable)

textElideMode :Qt::TextElideMode

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

The default value for all item views isQt::ElideRight.

Access functions:

Qt::TextElideModetextElideMode() const
voidsetTextElideMode(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:

ScrollModeverticalScrollMode() const
voidsetVerticalScrollMode(ScrollMode mode)

Member Function Documentation

QAbstractItemView::QAbstractItemView(QWidget * parent = 0)

Constructs an abstract item view with the givenparent.

QAbstractItemView::~QAbstractItemView()

Destroys the view.

[signal]void QAbstractItemView::activated(constQModelIndex & index)

This signal is emitted when the item specified byindex 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 alsoclicked(),doubleClicked(),entered(), andpressed().

[slot]void QAbstractItemView::clearSelection()

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

See alsosetSelection() andselectAll().

[signal]void QAbstractItemView::clicked(constQModelIndex & index)

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

See alsoactivated(),doubleClicked(),entered(), andpressed().

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

Closes the giveneditor, and releases it. Thehint 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 alsoedit() andcommitData().

void QAbstractItemView::closePersistentEditor(constQModelIndex & index)

Closes the persistent editor for the item at the givenindex.

See alsoopenPersistentEditor().

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

Commit the data in theeditor to the model.

See alsocloseEditor().

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

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

If you want to know about changes to items see thedataChanged() signal.

QModelIndex QAbstractItemView::currentIndex() const

Returns the model index of the current item.

See alsosetCurrentIndex().

[virtual protected slot]void QAbstractItemView::dataChanged(constQModelIndex & topLeft, constQModelIndex & bottomRight)

This slot is called when items are changed in the model. The changed items are those fromtopLeft tobottomRight inclusive. If just one item is changedtopLeft ==bottomRight.

[protected]QPoint QAbstractItemView::dirtyRegionOffset() const

Returns the offset of the dirty regions in the view.

If you usescrollDirtyRegion() and implement apaintEvent() in a subclass ofQAbstractItemView, you should translate the area given by the paint event with the offset returned from this function.

See alsoscrollDirtyRegion() andsetDirtyRegion().

[signal]void QAbstractItemView::doubleClicked(constQModelIndex & index)

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

See alsoclicked() andactivated().

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

Reimplemented fromQWidget::dragEnterEvent().

This function is called with the givenevent 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 alsodropEvent() andstartDrag().

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

Reimplemented fromQWidget::dragLeaveEvent().

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

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

Reimplemented fromQWidget::dragMoveEvent().

This function is called continuously with the givenevent 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 alsodropEvent() andstartDrag().

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

Reimplemented fromQWidget::dropEvent().

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

[protected]DropIndicatorPosition QAbstractItemView::dropIndicatorPosition() const

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

This function was introduced in Qt 4.1.

[slot]void QAbstractItemView::edit(constQModelIndex & index)

Starts editing the item corresponding to the givenindex 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, callsetCurrentIndex() before this function with the same model index.

See alsoQModelIndex::flags().

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

Starts editing the item atindex, creating an editor if necessary, and returns true if the view'sState is nowEditingState; otherwise returns false.

The action that caused the editing process is described bytrigger, and the associated event is specified byevent.

Editing can be forced by specifying thetrigger to beQAbstractItemView::AllEditTriggers.

See alsocloseEditor().

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

This function is called when the giveneditor has been destroyed.

See alsocloseEditor().

[signal]void QAbstractItemView::entered(constQModelIndex & index)

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

See alsoviewportEntered(),activated(),clicked(),doubleClicked(), andpressed().

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

Reimplemented fromQObject::event().

[protected]void QAbstractItemView::executeDelayedItemsLayout()

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

See alsoscheduleDelayedItemsLayout().

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

Reimplemented fromQWidget::focusInEvent().

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

See alsosetFocus() andfocusOutEvent().

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

Reimplemented fromQWidget::focusNextPrevChild().

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

Reimplemented fromQWidget::focusOutEvent().

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

See alsoclearFocus() andfocusInEvent().

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

Returns the horizontal offset of the view.

In the base class this is a pure virtual function.

See alsoverticalOffset().

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

Returns the model index of the item at the viewport coordinatespoint.

In the base class this is a pure virtual function.

See alsovisualRect().

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

Returns the widget for the item at the givenindex.

This function was introduced in Qt 4.1.

See alsosetIndexWidget().

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

Reimplemented fromQWidget::inputMethodEvent().

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

Reimplemented fromQWidget::inputMethodQuery().

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

Returns true if the item referred to by the givenindex 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.

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 withsetItemDelegate(), or the default one.

See alsosetItemDelegate().

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

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

QAbstractItemDelegate * QAbstractItemView::itemDelegateForColumn(int column) const

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

This function was introduced in Qt 4.2.

See alsosetItemDelegateForColumn(),itemDelegateForRow(), anditemDelegate().

QAbstractItemDelegate * QAbstractItemView::itemDelegateForRow(int row) const

Returns the item delegate used by this view and model for the givenrow, or 0 if no delegate has been assigned. You can callitemDelegate() to get a pointer to the current delegate for a given index.

This function was introduced in Qt 4.2.

See alsosetItemDelegateForRow(),itemDelegateForColumn(), andsetItemDelegate().

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

Reimplemented fromQWidget::keyPressEvent().

This function is called with the givenevent 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; theactivated() 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 alsoedit(),moveCursor(),keyboardSearch(), andtabKeyNavigation.

[virtual]void QAbstractItemView::keyboardSearch(constQString & search)

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

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

QAbstractItemModel * QAbstractItemView::model() const

Returns the model that this view is presenting.

See alsosetModel().

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

Reimplemented fromQWidget::mouseDoubleClickEvent().

This function is called with the givenevent when a mouse button is double clicked inside the widget. If the double-click is on a valid item it emits thedoubleClicked() signal and callsedit() on the item.

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

Reimplemented fromQWidget::mouseMoveEvent().

This function is called with the givenevent 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)

Reimplemented fromQWidget::mousePressEvent().

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

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

Reimplemented fromQWidget::mouseReleaseEvent().

This function is called with the givenevent 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 theclicked() signal if an item was being pressed.

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

Returns aQModelIndex object pointing to the next object in the view, based on the givencursorAction and keyboard modifiers specified bymodifiers.

In the base class this is a pure virtual function.

void QAbstractItemView::openPersistentEditor(constQModelIndex & index)

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

See alsoclosePersistentEditor().

[signal]void QAbstractItemView::pressed(constQModelIndex & index)

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

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

See alsoactivated(),clicked(),doubleClicked(), andentered().

[virtual slot]void QAbstractItemView::reset()

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.

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

Reimplemented fromQWidget::resizeEvent().

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

See alsoQWidget::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 alsosetRootIndex().

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

This slot is called when rows are about to be removed. The deleted rows are those under the givenparent fromstart toend inclusive.

See alsorowsInserted().

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

This slot is called when rows are inserted. The new rows are those under the givenparent fromstart toend inclusive. The base class implementation calls fetchMore() on the model to check for more data.

See alsorowsAboutToBeRemoved().

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

See alsoexecuteDelayedItemsLayout().

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

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 implementscrollContentsBy() in a subclass ofQAbstractItemView, call this function before you callQWidget::scroll() on the viewport. Alternatively, just callupdate().

See alsoscrollContentsBy(),dirtyRegionOffset(), andsetDirtyRegion().

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

Scrolls the view if necessary to ensure that the item atindex is visible. The view will try to position the item according to the givenhint.

In the base class this is a pure virtual function.

[slot]void QAbstractItemView::scrollToBottom()

Scrolls the view to the bottom.

This function was introduced in Qt 4.1.

See alsoscrollTo() andscrollToTop().

[slot]void QAbstractItemView::scrollToTop()

Scrolls the view to the top.

This function was introduced in Qt 4.1.

See alsoscrollTo() andscrollToBottom().

[virtual slot]void QAbstractItemView::selectAll()

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

See alsosetSelection(),selectedIndexes(), andclearSelection().

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

See alsoQItemSelectionModel::selectedIndexes().

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

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

See alsosetSelection().

[virtual protected]QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(constQModelIndex & index, constQEvent * event = 0) const

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

Reimplement this function to define your own selection behavior.

See alsosetSelection().

QItemSelectionModel * QAbstractItemView::selectionModel() const

Returns the current selection model.

See alsosetSelectionModel() andselectedIndexes().

[slot]void QAbstractItemView::setCurrentIndex(constQModelIndex & index)

Sets the current item to be the item atindex.

Unless the current selection mode isNoSelection, the item is also be 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 alsocurrentIndex(),currentChanged(), andselectionMode.

[protected]void QAbstractItemView::setDirtyRegion(constQRegion & region)

Marks the givenregion 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 alsoscrollDirtyRegion() anddirtyRegionOffset().

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

Sets the givenwidget on the item at the givenindex, passing the ownership of the widget to the viewport.

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

The givenwidget'sautoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the item at the givenindex.

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

setIndexWidget(index,newQLineEdit);...setIndexWidget(index,newQTextEdit);

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, subclassQItemDelegate instead.

This function was introduced in Qt 4.1.

See alsoindexWidget() andDelegate Classes.

void QAbstractItemView::setItemDelegate(QAbstractItemDelegate * delegate)

Sets the item delegate for this view and its model todelegate. 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 thecloseEditor() signal, and attempt to access, modify or close an editor that has already been closed.

See alsoitemDelegate().

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

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

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

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

This function was introduced in Qt 4.2.

See alsoitemDelegateForColumn(),setItemDelegateForRow(), anditemDelegate().

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

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

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

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

This function was introduced in Qt 4.2.

See alsoitemDelegateForRow(),setItemDelegateForColumn(), anditemDelegate().

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

Sets themodel for the view to present.

This function will create and set a new selection model, replacing any model that was previously set withsetSelectionModel(). 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 theirdeleteLater() functions to explicitly delete them.

The viewdoes 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 alsomodel(),selectionModel(), andsetSelectionModel().

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

Sets the root item to the item at the givenindex.

See alsorootIndex().

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

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

When implementing your own itemview setSelection should callselectionModel()->select(selection, flags) where selection is either an emptyQModelIndex or aQItemSelection that contains all items that are contained inrect.

See alsoselectionCommand() andselectedIndexes().

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

Sets the current selection model to the givenselectionModel.

Note that, if you callsetModel() after this function, the givenselectionModel 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 itsdeleteLater() function to explicitly delete it.

See alsoselectionModel(),setModel(), andclearSelection().

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

Sets the item view's state to the givenstate.

See alsostate().

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

Returns the width size hint for the specifiedcolumn 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 givencolumn.

See alsosizeHintForRow().

QSize QAbstractItemView::sizeHintForIndex(constQModelIndex & index) const

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

See alsosizeHintForRow() andsizeHintForColumn().

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

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

The returned height is calculated using the size hints of the givenrow'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 theQAbstractItemDelegate::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 givenrow.

See alsosizeHintForColumn().

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

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

[protected]State QAbstractItemView::state() const

Returns the item view's state.

See alsosetState().

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

Reimplemented fromQObject::timerEvent().

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

See alsoQObject::timerEvent().

[slot]void QAbstractItemView::update(constQModelIndex & index)

Updates the area occupied by the givenindex.

This function was introduced in Qt 4.3.

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

Updates the geometry of the child widgets of the view.

This function was introduced in Qt 4.4.

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

Returns the vertical offset of the view.

In the base class this is a pure virtual function.

See alsohorizontalOffset().

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

Returns aQStyleOptionViewItem 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.

See alsoentered().

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

Reimplemented fromQAbstractScrollArea::viewportEvent().

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

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

Returns the rectangle on the viewport occupied by the item atindex.

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 alsoindexAt() andvisualRegionForSelection().

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

Returns the region from the viewport of the items in the givenselection.

In the base class this is a pure virtual function.

See alsovisualRect() andselectedIndexes().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp