PySide6.QtWidgets.QListView¶
- class QListView¶
The
QListView
class provides a list or icon view onto a model. More…Inherited by:
QUndoView
,QListWidget
,QHelpIndexWidget
Synopsis¶
Properties¶
batchSizeᅟ
- The number of items laid out in each batch if layoutMode is set to Batchedflowᅟ
- Which direction the items layout should flowgridSizeᅟ
- The size of the layout gridisWrappingᅟ
- Whether the items layout should wrapitemAlignmentᅟ
- The alignment of each item in its celllayoutModeᅟ
- Determines whether the layout of items should happen immediately or be delayedmodelColumnᅟ
- The column in the model that is visiblemovementᅟ
- Whether the items can be moved freely, are snapped to a grid, or cannot be moved at allresizeModeᅟ
- Whether the items are laid out again when the view is resizedselectionRectVisibleᅟ
- If the selection rectangle should be visiblespacingᅟ
- The space around the items in the layoutuniformItemSizesᅟ
- Whether all items in the listview have the same sizeviewModeᅟ
- The view mode of the QListViewwordWrapᅟ
- The item text word-wrapping policy
Methods¶
def
__init__()
def
batchSize()
def
contentsSize()
def
flow()
def
gridSize()
def
isRowHidden()
def
isWrapping()
def
itemAlignment()
def
layoutMode()
def
modelColumn()
def
movement()
def
rectForIndex()
def
resizeContents()
def
resizeMode()
def
setBatchSize()
def
setFlow()
def
setGridSize()
def
setLayoutMode()
def
setModelColumn()
def
setMovement()
def
setResizeMode()
def
setRowHidden()
def
setSpacing()
def
setViewMode()
def
setWordWrap()
def
setWrapping()
def
spacing()
def
viewMode()
def
wordWrap()
Signals¶
def
indexesMoved()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
A
QListView
presents items stored in a model, either as a simple non-hierarchical list, or as a collection of icons. This class is used to provide lists and icon views that were previously provided by theQListBox
andQIconView
classes, but using the more flexible approach provided by Qt’s model/view architecture.The
QListView
class is one of the Model/View Classes and is part of Qt’s model/view framework .This view does not display horizontal or vertical headers; to display a list of items with a horizontal header, use
QTreeView
instead.QListView
implements the interfaces defined by theQAbstractItemView
class to allow it to display data provided by models derived from the QAbstractItemModel class.Items in a list view can be displayed using one of two view modes: In
ListMode
, the items are displayed in the form of a simple list; inIconMode
, the list view takes the form of an icon view in which the items are displayed with icons like files in a file manager. By default, the list view is inListMode
. To change the view mode, use thesetViewMode()
function, and to determine the current view mode, useviewMode()
.Items in these views are laid out in the direction specified by the
flow()
of the list view. The items may be fixed in place, or allowed to move, depending on the view’smovement()
state.If the items in the model cannot be completely laid out in the direction of flow, they can be wrapped at the boundary of the view widget; this depends on
isWrapping()
. This property is useful when the items are being represented by an icon view.The
resizeMode()
andlayoutMode()
govern how and when the items are laid out. Items are spaced according to theirspacing()
, and can exist within a notional grid of size specified bygridSize()
. The items can be rendered as large or small icons depending on theiriconSize()
.Improving Performance¶
It is possible to give the view hints about the data it is handling in order to improve its performance when displaying large numbers of items. One approach that can be taken for views that are intended to display items with equal sizes is to set the
uniformItemSizes
property to true.See also
- class Movement¶
Constant
Description
QListView.Static
The items cannot be moved by the user.
QListView.Free
The items can be moved freely by the user.
QListView.Snap
The items snap to the specified grid when moved; see
setGridSize()
.
- class Flow¶
Constant
Description
QListView.LeftToRight
The items are laid out in the view from the left to the right.
QListView.TopToBottom
The items are laid out in the view from the top to the bottom.
- class ResizeMode¶
Constant
Description
QListView.Fixed
The items will only be laid out the first time the view is shown.
QListView.Adjust
The items will be laid out every time the view is resized.
- class LayoutMode¶
Constant
Description
QListView.SinglePass
The items are laid out all at once.
QListView.Batched
The items are laid out in batches of
batchSize
items.See also
- class ViewMode¶
Constant
Description
QListView.ListMode
The items are laid out using
TopToBottom
flow, with Small size and Static movementQListView.IconMode
The items are laid out using
LeftToRight
flow, with Large size and Free movement
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property batchSizeᅟ: int¶
This property holds the number of items laid out in each batch if
layoutMode
is set toBatched
..The default value is 100.
- Access functions:
- property flowᅟ: QListView.Flow¶
This property holds which direction the items layout should flow..
If this property is
LeftToRight
, the items will be laid out left to right. If theisWrapping
property istrue
, the layout will wrap when it reaches the right side of the visible area. If this property isTopToBottom
, the items will be laid out from the top of the visible area, wrapping when it reaches the bottom.Setting this property when the view is visible will cause the items to be laid out again.
By default, this property is set to
TopToBottom
.See also
This property holds the size of the layout grid.
This property is the size of the grid in which the items are laid out. The default is an empty size which means that there is no grid and the layout is not done in a grid. Setting this property to a non-empty size switches on the grid layout. (When a grid layout is in force the
spacing
property is ignored.)Setting this property when the view is visible will cause the items to be laid out again.
See also
- Access functions:
- property isWrappingᅟ: bool¶
This property holds whether the items layout should wrap..
This property holds whether the layout should wrap when there is no more space in the visible area. The point at which the layout wraps depends on the
flow
property.Setting this property when the view is visible will cause the items to be laid out again.
By default, this property is
false
.See also
- Access functions:
- property itemAlignmentᅟ: Combination of Qt.AlignmentFlag¶
This property holds the alignment of each item in its cell.
This is only supported in
ListMode
withTopToBottom
flow and with wrapping enabled. The default alignment is 0, which means that an item fills its cell entirely.- Access functions:
- property layoutModeᅟ: QListView.LayoutMode¶
This property determines whether the layout of items should happen immediately or be delayed..
This property holds the layout mode for the items. When the mode is
SinglePass
(the default), the items are laid out all in one go. When the mode isBatched
, the items are laid out in batches ofbatchSize
items, while processing events. This makes it possible to instantly view and interact with the visible items while the rest are being laid out.See also
- Access functions:
- property modelColumnᅟ: int¶
This property holds the column in the model that is visible.
By default, this property contains 0, indicating that the first column in the model will be shown.
- Access functions:
- property movementᅟ: QListView.Movement¶
This property holds whether the items can be moved freely, are snapped to a grid, or cannot be moved at all..
This property determines how the user can move the items in the view.
Static
means that the items can’t be moved by the user.Free
means that the user can drag and drop the items to any position in the view.Snap
means that the user can drag and drop the items, but only to the positions in a notional grid signified by thegridSize
property.Setting this property when the view is visible will cause the items to be laid out again.
By default, this property is set to
Static
.See also
- Access functions:
- property resizeModeᅟ: QListView.ResizeMode¶
This property holds whether the items are laid out again when the view is resized..
If this property is
Adjust
, the items will be laid out again when the view is resized. If the value isFixed
, the items will not be laid out when the view is resized.By default, this property is set to
Fixed
.- Access functions:
- property selectionRectVisibleᅟ: bool¶
This property holds if the selection rectangle should be visible.
If this property is
true
then the selection rectangle is visible; otherwise it will be hidden.Note
The selection rectangle will only be visible if the selection mode is in a mode where more than one item can be selected; i.e., it will not draw a selection rectangle if the selection mode is
SingleSelection
.By default, this property is
false
.- Access functions:
- property spacingᅟ: int¶
This property holds the space around the items in the layout.
This property is the size of the empty space that is padded around an item in the layout.
Setting this property when the view is visible will cause the items to be laid out again.
By default, this property contains a value of 0.
See also
- Access functions:
- property uniformItemSizesᅟ: bool¶
This property holds whether all items in the listview have the same size.
This property should only be set to true if it is guaranteed that all items in the view have the same size. This enables the view to do some optimizations for performance purposes.
By default, this property is
false
.- Access functions:
- property viewModeᅟ: QListView.ViewMode¶
This property holds the view mode of the
QListView
..This property will change the other unset properties to conform with the set view mode.
QListView
-specific properties that have already been set will not be changed, unlessclearPropertyFlags()
has been called.Setting the view mode will enable or disable drag and drop based on the selected movement. For
ListMode
, the default movement isStatic
(drag and drop disabled); forIconMode
, the default movement isFree
(drag and drop enabled).See also
- Access functions:
- property wordWrapᅟ: bool¶
This property holds the item text word-wrapping policy.
If this property is
true
then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property isfalse
by default.Please note that even if wrapping is enabled, the cell will not be expanded to make room for the text. It will print ellipsis for text that cannot be shown, according to the view’s
textElideMode
.- Access functions:
Creates a new
QListView
with the givenparent
to view a model. UsesetModel()
to set the model.- batchSize()¶
- Return type:
int
See also
Getter of property
batchSizeᅟ
.- clearPropertyFlags()¶
Clears the
QListView
-specific property flags. SeeviewMode
.Properties inherited from
QAbstractItemView
are not covered by the property flags. Specifically,dragEnabled
andacceptsDrops
are computed byQListView
when callingsetMovement()
orsetViewMode()
.Getter of property
flowᅟ
.- gridSize()¶
- Return type:
See also
Getter of property
gridSizeᅟ
.- indexesMoved(indexes)¶
- Parameters:
indexes – .list of QModelIndex
This signal is emitted when the specified
indexes
are moved in the view.- isRowHidden(row)¶
- Parameters:
row – int
- Return type:
bool
Returns
true
if therow
is hidden; otherwise returnsfalse
.- isSelectionRectVisible()¶
- Return type:
bool
Getter of property
selectionRectVisibleᅟ
.- isWrapping()¶
- Return type:
bool
Getter of property
isWrappingᅟ
.- itemAlignment()¶
- Return type:
Combination of
AlignmentFlag
See also
Getter of property
itemAlignmentᅟ
.- layoutMode()¶
- Return type:
See also
Getter of property
layoutModeᅟ
.- modelColumn()¶
- Return type:
int
See also
Getter of property
modelColumnᅟ
.- movement()¶
- Return type:
See also
Getter of property
movementᅟ
.- rectForIndex(index)¶
- Parameters:
index –
QModelIndex
- Return type:
Returns the rectangle of the item at position
index
in the model. The rectangle is in contents coordinates.See also
visualRect()
- resizeContents(width, height)¶
- Parameters:
width – int
height – int
- resizeMode()¶
- Return type:
See also
Getter of property
resizeModeᅟ
.- setBatchSize(batchSize)¶
- Parameters:
batchSize – int
See also
Setter of property
batchSizeᅟ
.Setter of property
flowᅟ
.Setter of property
gridSizeᅟ
.- setItemAlignment(alignment)¶
- Parameters:
alignment – Combination of
AlignmentFlag
See also
Setter of property
itemAlignmentᅟ
.- setLayoutMode(mode)¶
- Parameters:
mode –
LayoutMode
See also
Setter of property
layoutModeᅟ
.- setModelColumn(column)¶
- Parameters:
column – int
See also
Setter of property
modelColumnᅟ
.Setter of property
movementᅟ
.- setPositionForIndex(position, index)¶
- Parameters:
position –
QPoint
index –
QModelIndex
Sets the contents position of the item at
index
in the model to the givenposition
. If the list view’s movement mode is Static or its view mode is ListView, this function will have no effect.- setResizeMode(mode)¶
- Parameters:
mode –
ResizeMode
See also
Setter of property
resizeModeᅟ
.- setRowHidden(row, hide)¶
- Parameters:
row – int
hide – bool
If
hide
is true, the givenrow
will be hidden; otherwise therow
will be shown.See also
- setSelectionRectVisible(show)¶
- Parameters:
show – bool
See also
Setter of property
selectionRectVisibleᅟ
.Setter of property
spacingᅟ
.- setUniformItemSizes(enable)¶
- Parameters:
enable – bool
See also
Setter of property
uniformItemSizesᅟ
.Setter of property
viewModeᅟ
.- setWordWrap(on)¶
- Parameters:
on – bool
See also
Setter of property
wordWrapᅟ
.- setWrapping(enable)¶
- Parameters:
enable – bool
See also
Setter of property
isWrappingᅟ
.- spacing()¶
- Return type:
int
See also
Getter of property
spacingᅟ
.- uniformItemSizes()¶
- Return type:
bool
See also
Getter of property
uniformItemSizesᅟ
.- viewMode()¶
- Return type:
See also
Getter of property
viewModeᅟ
.- wordWrap()¶
- Return type:
bool
See also
Getter of property
wordWrapᅟ
.