QAbstractItemView Class Reference |
|
|
The QAbstractItemView class provides the basic functionality for item view classes.
QAbstractItemView class is the base class for every standard view that uses a QAbstractItemModel. QAbstractItemView is an abstract class and cannot itself be instantiated. It provides a standard interface for interoperating with models through the signals and slots mechanism, enabling subclasses to be kept up-to-date with changes to their models. This class provides standard support for keyboard and mouse navigation, viewport scrolling, item editing, and selections.
The QAbstractItemView class is one of the Model/View Classes and is part of Qt's model/view framework.
The view classes that inherit QAbstractItemView only need to implement their own view-specific functionality, such as drawing items, returning the geometry of items, finding items, etc.
QAbstractItemView provides common slots such as edit() and setCurrentIndex(). Many protected slots are also provided, including dataChanged(), rowsInserted(), rowsAboutToBeRemoved(), columnsInserted(), columnsRemoved(), selectionChanged(), and currentChanged().
The root item is returned by rootIndex(), and the current item by currentIndex(). To make sure that an item is visible use scrollTo().
Some of QAbstractItemView's functions are concerned with scrolling, for example setHorizontalFactor() and setVerticalFactor(). Several other functions are concerned with selection control; for example setSelectionMode(), and setSelectionBehavior(). This class provides a default selection model to work with (selectionModel()), but this can be replaced by using setSelectionModel() with an instance of QItemSelectionModel.
When implimenting a view that will have scrollbars you want to overload resizeEvent to set the scrollbars range so they will turn of and off, for example:
horizontalScrollBar()->setRange(0, realWidth - width());
For complete control over the display and editing of items you can specify a delegate with setItemDelegate().
QAbstractItemView provides a lot of protected functions. Some are concerned with editing, for example, edit(), and commitData(), whilst others are keyboard and mouse event handlers.
See also Model/View Programming and QAbstractItemModel.
This enum describes the different ways to navigate between items,
Constant | Value | Description |
---|---|---|
QAbstractItemView::MoveUp | 0 | Move to the item above the current item. |
QAbstractItemView::MoveDown | 1 | Move to the item below the current item. |
QAbstractItemView::MoveLeft | 2 | Move to the item left of the current item. |
QAbstractItemView::MoveRight | 3 | Move to the item right of the current item. |
QAbstractItemView::MoveHome | 4 | Move to the top-left corner item. |
QAbstractItemView::MoveEnd | 5 | Move to the bottom-right corner item. |
QAbstractItemView::MovePageUp | 6 | Move one page up above the current item. |
QAbstractItemView::MovePageDown | 7 | Move one page down below the current item. |
QAbstractItemView::MoveNext | 8 | Move to the item after the current item. |
QAbstractItemView::MovePrevious | 9 | Move to the item before the current item. |
See also moveCursor().
This enum describes actions which will initiate item editing.
Constant | Value | Description |
---|---|---|
QAbstractItemView::NoEditTriggers | 0 | No editing possible. |
QAbstractItemView::CurrentChanged | 1 | Editing start whenever current item changes. |
QAbstractItemView::DoubleClicked | 2 | Editing starts when an item is double clicked. |
QAbstractItemView::SelectedClicked | 4 | Editing starts when clicking on an already selected item. |
QAbstractItemView::EditKeyPressed | 8 | Editing starts when an edit key has been pressed over an item. |
QAbstractItemView::AnyKeyPressed | 16 | Editing starts when any key is pressed over an item. |
QAbstractItemView::AllEditTriggers | 31 | Editing starts for all above actions. |
The EditTriggers type is a typedef for QFlags<EditTrigger>. It stores an OR combination of EditTrigger values.
Constant | Value | Description |
---|---|---|
QAbstractItemView::EnsureVisible | 0 | Scroll to ensure that the item is visible. |
QAbstractItemView::PositionAtTop | 1 | Scroll to position the item at the top of the viewport. |
QAbstractItemView::PositionAtBottom | 2 | Scroll to position the item at the bottom of the viewport. |
Constant | Value | Description |
---|---|---|
QAbstractItemView::SelectItems | 0 | Selecting single items. |
QAbstractItemView::SelectRows | 1 | Selecting only rows. |
QAbstractItemView::SelectColumns | 2 | Selecting only columns. |
This enum indicates how the view responds to user selections:
Constant | Value | Description |
---|---|---|
QAbstractItemView::SingleSelection | 1 | When the user selects an item, any already-selected item becomes unselected, and the user cannot unselect the selected item. |
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. |
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. |
QAbstractItemView::NoSelection | 0 | Items cannot be selected. |
In other words, SingleSelection is a real single-selection list view, MultiSelection a real multi-selection list view, ExtendedSelection is a list view in which users can select multiple items, but usually want to select either just one or a range of contiguous items, and NoSelection is a list view where the user can navigate without selecting items.
Describes the different states the view can be in. This is usually only interesting when reimplementing your own view.
Constant | Value | Description |
---|---|---|
QAbstractItemView::NoState | 0 | The is the default state. |
QAbstractItemView::DraggingState | 1 | The user is dragging items. |
QAbstractItemView::DragSelectingState | 2 | The user is selecting items. |
QAbstractItemView::EditingState | 3 | The user is editing an item in a widget editor. |
QAbstractItemView::ExpandingState | 4 | The user is opening a branch of items. |
QAbstractItemView::CollapsingState | 5 | The user is closing a branch of items. |
This property holds whether to draw the background using alternating colors.
If this property is true, the item background will be drawn using QPalette::Base and QPalette::AlternateBase; otherwise the background will be drawn using the QPalette::Base color.
By default, this property is false.
Access functions:
This property holds whether autoscrolling in drag move events is enabled.
If this property is set to true (the default), the QAbstractItemView automatically scrolls the contents of the view if the user drags within 16 pixels of the viewport edge. This only works if the viewport accepts drops. Autoscroll is switched off by setting this property to false.
Access functions:
This property holds whether the view supports dragging of its own items.
Access functions:
This property holds which actions will initiate item editing.
This property is a selection of flags defined by EditTrigger, combined using the OR operator. The view will only initiate the editing of an item if the action performed is set in this property.
Access functions:
This property holds the size of items.
Setting this property when the view is visible will cause the items to be laid out again.
Access functions:
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:
See also SelectionMode and SelectionBehavior.
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:
See also SelectionMode and SelectionBehavior.
This property holds whether the drop indicator is shown when dragging items and dropping.
Access functions:
This property holds whether item navigation with tab and backtab is enabled.
Access functions:
This property holds the the position of the "..." in elided text.
Access functions:
Constructs an abstract item view with the given parent.
Destroys the view.
This signal is emitted when the item specified by index is activated by the user (e.g., by single- or double-clicking the item, depending on the platform).
See also clicked(), doubleClicked(), entered(), and pressed().
Clears all selected items.
This signal is emitted when a mouse button is clicked. The item the mouse was clicked on is specified by index (which may be invalid if the mouse was not clicked on an item).
See also activated(), doubleClicked(), entered(), and pressed().
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().
Closes the persistent editor for the item at the given index.
Commit the data in the editor to the model.
See also closeEditor().
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.
Returns the model index of the current item.
See also setCurrentIndex().
This slot is called when items are changed in the model. The changed items are those from topLeft to bottomRight inclusive. If just one item is changed topLeft == bottomRight.
Returns the offset of the dirty regions in the view.
If you use scrollDirtyRegion() and implementa 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().
This signal is emitted when a mouse button is double-clicked. The item the mouse was double-clicked on is specified by index (which may be invalid if the mouse was not double-clicked on an item).
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.
Reimplemented from QWidget.
See also dropEvent() and startDrag().
This function is called when the item being dragged leaves the view. The event describes the state of the drag and drop operation.
Reimplemented from QWidget.
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.
Reimplemented from QWidget.
See also dropEvent() and startDrag().
This function is called with the given event when a drop event occurs over the widget. If there's a valid item under the mouse pointer when the drop occurs, the drop event is accepted; otherwise it is ignored.
Reimplemented from QWidget.
See also startDrag().
Starts editing the item item at index if it is editable.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Starts editing the item at index, creating an editor if necessary, and returns true if the view's State is now EditingState; otherwise returns false.
The action that caused the editing process is described by trigger, and the associated event is specified by event.
See also closeEditor().
Remove the editor editor from the map.
This signal is emitted when the mouse cursor enters the item specified by index.
See also viewportEntered(), activated(), clicked(), doubleClicked(), and pressed().
Executes the scheduled layouts without waiting for the event processing to begin.
See also scheduleDelayedItemsLayout().
This function is called with the given event when the widget obtains the focus. By default, the event is ignored.
Reimplemented from QWidget.
See also setFocus() and focusOutEvent().
This function is called with the given event when the widget obtains the focus. By default, the event is ignored.
Reimplemented from QWidget.
See also clearFocus() and focusInEvent().
Returns the horizontal offset of the view.
In the base class this is a pure virtual function.
Returns the horizontal scrollbar's steps per item.
See also setHorizontalStepsPerItem() and verticalStepsPerItem().
Returns the model index of the item at point p.
In the base class this is a pure virtual function.
Returns true if the item refered to by the given index is hidden, otherwise returns false.
In the base class this is a pure virtual function.
Returns the item delegate used by this view and model. This is either one set with setItemDelegate(), or the default one.
See also setItemDelegate().
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, and emits the returnPressed(), spacePressed(), and deletePressed() signals if the associated key is pressed. This function is where editing is initiated by key press, e.g. if F2 is pressed.
Reimplemented from QWidget.
See also edit().
Moves to and selects the item best matching the string search. If no item is found nothing happens.
Returns the model that this view is presenting.
See also setModel().
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.
Reimplemented from QWidget.
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.
Reimplemented from QWidget.
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.
Reimplemented from QWidget.
This function is called with the given event when a mouse button is released while the cursor is inside the widget. It will emit the clicked() signal if an item was being pressed.
Reimplemented from QWidget.
Moves the cursor in the view according to the given cursorAction and keyboard modifiers specified by modifiers.
Opens a persistent editor on the item at the given index. If no editor exists, the delegate will create a new editor.
This signal is emitted when a mouse button is pressed. The item the mouse was pressed on is specified by index (which may be invalid if the mouse was not pressed on an item).
See also activated(), clicked(), doubleClicked(), and entered().
Reset the internal state of the view.
This function is called with the given event when a resize event is sent to the widget.
Reimplemented from QWidget.
See also QWidget::resizeEvent().
Returns the model index of the model's root item. The root item is the parent item to the views toplevel items. The root can be invalid.
See also setRootIndex().
This slot is called when rows are about to be removed. The deleted rows are those under the given parent from start to end inclusive. The base class implementation does nothing.
See also rowsInserted().
This slot is called when rows are inserted. The new rows are those under the given parent from start to end inclusive. The base class implementation calls fetchMore() on the model to check for more data.
See also rowsAboutToBeRemoved().
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().
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() and dirtyRegionOffset().
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.
Selects all non-hidden items.
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.
The default implementation does nothing.
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.
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.
Returns the current selection.
See also setSelectionModel() and clearSelection().
Sets the current item to be the itm at index.
See also currentIndex().
Sets the horizontal scrollbar's steps per item to steps.
This is the number of steps used by the horizontal scrollbar to represent the width of an item.
See also horizontalStepsPerItem() and setVerticalStepsPerItem().
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.
See also itemDelegate().
Sets the model for the view to present.
See also model().
Sets the root item to the item at index.
See also rootIndex().
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().
Sets the current selection to the given selectionModel.
See also selectionModel() and clearSelection().
Sets the item view's state to the given state
See also state().
Sets the vertical scrollbar's steps per item to steps.
This is the number of steps used by the vertical scrollbar to represent the height of an item.
See also verticalStepsPerItem() and setHorizontalStepsPerItem().
Returns the width size hint for the specified column or -1 if there is no model.
Returns the size hint for the item with the specified index or an invalid size for invalid indexes.
Returns the height size hint for the specified row or -1 if there is no model.
Starts a drag by calling drag->start() using the given supportedActions.
Returns the item view's state.
See also setState().
This function is called with the given event when a timer event is sent to the widget.
Reimplemented from QObject.
See also QObject::timerEvent().
Returns the vertical offset of the view.
In the base class this is a pure virtual function.
Returns the vertical scrollbar's steps per item.
See also setVerticalStepsPerItem() and horizontalStepsPerItem().
Returns QStyleOptionViewItem structure populated with the view's palette, font, state, alignments etc.
This signal is emitted when the mouse cursor enters the viewport.
See also entered().
This function is used to handle tool tips, status tips, and What's This? mode, if the given event is a QEvent::ToolTip, a QEvent::WhatsThis, or a QEvent::StatusTip. It passes all other events on to its base class viewportEvent() handler.
Reimplemented from QAbstractScrollArea.
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.
Returns the region from the viewport of the items in the given selection.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com