QStandardItem Class Reference

[ QtGui module]

QStandardItem 类提供的项用于 QStandardItemModel 类。 更多...

类型

方法

Special Methods


详细描述

QStandardItem 类提供的项用于 QStandardItemModel 类。

Items usually contain text, icons, or checkboxes.

Each item can have its own background brush which is set with the setBackground () function. The current background brush can be found with background (). The text label for each item can be rendered with its own font and brush. These are specified with the setFont () 和 setForeground () functions, and read with font () 和 foreground ().

By default, items are enabled, editable, selectable, checkable, and can be used both as the source of a drag and drop operation and as a drop target. Each item's flags can be changed by calling setFlags (). Checkable items can be checked and unchecked with the setCheckState () 函数。 The corresponding checkState () function indicates whether the item is currently checked.

You can store application-specific data in an item by calling setData ().

Each item can have a two-dimensional table of child items. This makes it possible to build hierarchies of items. The typical hierarchy is the tree, in which case the child table is a table with a single column (a list).

The dimensions of the child table can be set with setRowCount () 和 setColumnCount (). Items can be positioned in the child table with setChild (). Get a pointer to a child item with child (). New rows and columns of children can also be inserted with insertRow () 和 insertColumn (), or appended with appendRow () 和 appendColumn (). When using the append and insert functions, the dimensions of the child table will grow as needed.

An existing row of children can be removed with removeRow () 或 takeRow (); correspondingly, a column can be removed with removeColumn () 或 takeColumn ().

An item's children can be sorted by calling sortChildren ().

子类化

When subclassing QStandardItem to provide custom items, it is possible to define new types for them so that they can be distinguished from the base class. The type () function should be reimplemented to return a new type value equal to or greater than UserType .

Reimplement data () 和 setData () if you want to perform custom handling of data queries and/or control how an item's data is represented.

Reimplement clone () if you want QStandardItemModel to be able to create instances of your custom item class on demand (见 QStandardItemModel.setItemPrototype ()).

Reimplement read () 和 write () if you want to control how items are represented in their serialized form.

Reimplement operator< () if you want to control the semantics of item comparison. operator< () determines the sorted order when sorting items with sortChildren () 或采用 QStandardItemModel.sort ().


类型文档编制

QStandardItem.ItemType

This enum describes the types that are used to describe standard 项。

常量 描述
QStandardItem.Type 0 The default type for standard items.
QStandardItem.UserType 1000 The minimum value for custom types. Values below UserType are reserved by Qt.

可以定义新用户类型在 QStandardItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

另请参阅 type ().


方法文档编制

QStandardItem.__init__ ( self )

Constructs an item.

QStandardItem.__init__ ( self , QString  text )

Constructs an item with the given text .

QStandardItem.__init__ ( self , QIcon   icon , QString  text )

Constructs an item with the given icon and text .

QStandardItem.__init__ ( self , int  rows , int  columns  = 1)

Constructs an item with rows rows and columns columns of child items.

QStandardItem.__init__ ( self , QStandardItem   other )

构造副本为 other 。注意 model () is not copied.

此函数是有用的,当重实现 clone ().

QString QStandardItem.accessibleDescription ( self )

Returns the item's accessible description.

The accessible description is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

另请参阅 setAccessibleDescription () and accessibleText ().

QString QStandardItem.accessibleText ( self )

Returns the item's accessible text.

The accessible text is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

另请参阅 setAccessibleText () 和 accessibleDescription ().

QStandardItem.appendColumn ( self , list-of-QStandardItem  aitems )

aitems argument has it's ownership transferred to Qt.

Appends a column containing items . If necessary, the row count is increased to the size of items .

另请参阅 insertColumn ().

QStandardItem.appendRow ( self , list-of-QStandardItem  aitems )

aitems argument has it's ownership transferred to Qt.

Appends a row containing items . If necessary, the column count is increased to the size of items .

另请参阅 insertRow ().

QStandardItem.appendRow ( self , QStandardItem   aitem )

aitem argument has it's ownership transferred to Qt.

这是重载函数。

Appends a row containing item .

When building a list or a tree that has only one column, this function provides a convenient way to append a single new item.

QStandardItem.appendRows ( self , list-of-QStandardItem  aitems )

aitems argument has it's ownership transferred to Qt.

Appends rows containing items . The column count will not change.

另请参阅 insertRow ().

QBrush QStandardItem.background ( self )

Returns the brush used to render the item's background.

另请参阅 foreground () 和 setBackground ().

Qt.CheckState QStandardItem.checkState ( self )

Returns the checked state of the item.

另请参阅 setCheckState () 和 isCheckable ().

QStandardItem QStandardItem.child ( self , int  row , int  column  = 0)

Returns the child item at ( row , column ) if one has been set; otherwise returns 0.

另请参阅 setChild (), takeChild (),和 parent ().

QStandardItem QStandardItem.clone ( self )

Returns a copy of this item. The item's children are not copied.

When subclassing QStandardItem , you can reimplement this function to provide QStandardItemModel with a factory that it can use to create new items on demand.

另请参阅 QStandardItemModel.setItemPrototype () and operator= ().

int QStandardItem.column ( self )

Returns the column where the item is located in its parent's child table, or -1 if the item has no parent.

另请参阅 row () 和 parent ().

int QStandardItem.columnCount ( self )

Returns the number of child item columns that the item has.

另请参阅 setColumnCount () 和 rowCount ().

QVariant QStandardItem.data ( self , int  role  = Qt.UserRole+1)

Returns the item's data for the given role , or an invalid QVariant if there is no data for the role.

注意: The default implementation treats Qt.EditRole and Qt.DisplayRole as referring to the same data.

另请参阅 setData ().

QStandardItem.emitDataChanged ( self )

Causes the model associated with this item to emit a dataChanged () signal for this item.

You normally only need to call this function if you have subclassed QStandardItem and reimplemented data () and/or setData ().

该函数在 Qt 4.4 引入。

另请参阅 setData ().

Qt.ItemFlags QStandardItem.flags ( self )

Returns the item flags for the item.

The item flags determine how the user can interact with the 项。

By default, items are enabled, editable, selectable, checkable, and can be used both as the source of a drag and drop operation and as a drop target.

另请参阅 setFlags ().

QFont QStandardItem.font ( self )

Returns the font used to render the item's text.

另请参阅 setFont ().

QBrush QStandardItem.foreground ( self )

Returns the brush used to render the item's foreground (e.g. text).

另请参阅 setForeground () 和 background ().

bool QStandardItem.hasChildren ( self )

Returns true if this item has any children; otherwise returns false.

另请参阅 rowCount (), columnCount (),和 child ().

QIcon QStandardItem.icon ( self )

Returns the item's icon.

另请参阅 setIcon () 和 iconSize .

QModelIndex QStandardItem.index ( self )

返回 QModelIndex associated with this item.

When you need to invoke item functionality in a QModelIndex -based API (e.g. QAbstractItemView ), you can call this function to obtain an index that corresponds to the item's location in the model.

If the item is not associated with a model, an invalid QModelIndex 被返回。

另请参阅 model () and QStandardItemModel.itemFromIndex ().

QStandardItem.insertColumn ( self , int  column , list-of-QStandardItem  items )

items argument has it's ownership transferred to Qt.

Inserts a column at column containing items 。若 necessary, the row count is increased to the size of items .

另请参阅 insertColumns () 和 insertRow ().

QStandardItem.insertColumns ( self , int  column , int  count )

插入 count columns of child items at column column .

另请参阅 insertColumn () 和 insertRows ().

QStandardItem.insertRow ( self , int  row , list-of-QStandardItem  items )

items argument has it's ownership transferred to Qt.

Inserts a row at row containing items 。若 necessary, the column count is increased to the size of items .

另请参阅 insertRows () 和 insertColumn ().

QStandardItem.insertRow ( self , int  arow , QStandardItem   aitem )

aitem argument has it's ownership transferred to Qt.

这是重载函数。

Inserts a row at row containing item .

When building a list or a tree that has only one column, this function provides a convenient way to insert a single new item.

QStandardItem.insertRows ( self , int  row , int  count )

插入 items at row . The column count wont be 改变。

另请参阅 insertRow () 和 insertColumn ().

QStandardItem.insertRows ( self , int  row , list-of-QStandardItem  items )

items argument has it's ownership transferred to Qt.

插入 count rows of child items at row row .

另请参阅 insertRow () 和 insertColumns ().

bool QStandardItem.isCheckable ( self )

Returns whether the item is user-checkable.

默认值为 false。

另请参阅 setCheckable (), checkState (),和 isTristate ().

bool QStandardItem.isDragEnabled ( self )

Returns whether the item is drag enabled. An item that is drag enabled can be dragged by the user.

默认值为 true。

Note that item dragging must be enabled in the view for dragging to work; see QAbstractItemView.dragEnabled .

另请参阅 setDragEnabled (), isDropEnabled (),和 flags ().

bool QStandardItem.isDropEnabled ( self )

Returns whether the item is drop enabled. When an item is drop enabled, it can be used as a drop target.

默认值为 true。

另请参阅 setDropEnabled (), isDragEnabled (),和 flags ().

bool QStandardItem.isEditable ( self )

Returns whether the item can be edited by the user.

When an item is editable (and enabled), the user can edit the item by invoking one of the view's edit triggers; see QAbstractItemView.editTriggers .

默认值为 true。

另请参阅 setEditable () 和 flags ().

bool QStandardItem.isEnabled ( self )

Returns whether the item is enabled.

When an item is enabled, the user can interact with it. The possible types of interaction are specified by the other item flags, such as isEditable () 和 isSelectable ().

默认值为 true。

另请参阅 setEnabled () 和 flags ().

bool QStandardItem.isSelectable ( self )

Returns whether the item is selectable by the user.

默认值为 true。

另请参阅 setSelectable () 和 flags ().

bool QStandardItem.isTristate ( self )

Returns whether the item is tristate; that is, if it's checkable with three separate states.

默认值为 false。

另请参阅 setTristate (), isCheckable (),和 checkState ().

QStandardItemModel QStandardItem.model ( self )

返回 QStandardItemModel that this item belongs to.

If the item is not a child of another item that belongs to the model, this function returns 0.

另请参阅 index ().

QStandardItem QStandardItem.parent ( self )

Returns the item's parent item, or 0 if the item has no parent.

另请参阅 child ().

QStandardItem.read ( self , QDataStream   in )

读取项从流 in . Only the data and flags of the item are read, not the child items.

另请参阅 write ().

QStandardItem.removeColumn ( self , int  column )

移除给定 column . The items that were in the column are deleted.

另请参阅 takeColumn (), removeColumns (),和 removeRow ().

QStandardItem.removeColumns ( self , int  column , int  count )

移除 count columns at column column . The items that were in those columns are deleted.

另请参阅 removeColumn () 和 removeRows ().

QStandardItem.removeRow ( self , int  row )

移除给定 row . The items that were in the row are deleted.

另请参阅 takeRow (), removeRows (),和 removeColumn ().

QStandardItem.removeRows ( self , int  row , int  count )

移除 count rows at row row . The items that were in those rows are deleted.

另请参阅 removeRow () 和 removeColumn ().

int QStandardItem.row ( self )

Returns the row where the item is located in its parent's child table, or -1 if the item has no parent.

另请参阅 column () and parent ().

int QStandardItem.rowCount ( self )

Returns the number of child item rows that the item has.

另请参阅 setRowCount () 和 columnCount ().

QStandardItem.setAccessibleDescription ( self , QString  aaccessibleDescription )

Sets the item's accessible description to the string specified by accessibleDescription .

The accessible description is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

另请参阅 accessibleDescription () and setAccessibleText ().

QStandardItem.setAccessibleText ( self , QString  aaccessibleText )

Sets the item's accessible text to the string specified by accessibleText .

The accessible text is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

另请参阅 accessibleText () 和 setAccessibleDescription ().

QStandardItem.setBackground ( self , QBrush   abrush )

Sets the item's background brush to the specified brush .

另请参阅 background () 和 setForeground ().

QStandardItem.setCheckable ( self , bool  checkable )

Sets whether the item is user-checkable. If checkable is true, the item can be checked by the user; otherwise, the user cannot check the item.

The item delegate will render a checkable item with a check box next to the item's text.

另请参阅 isCheckable (), setCheckState (),和 setTristate ().

QStandardItem.setCheckState ( self , Qt.CheckState   acheckState )

Sets the check state of the item to be state .

另请参阅 checkState () 和 setCheckable ().

QStandardItem.setChild ( self , int  row , int  column , QStandardItem   item )

item argument has it's ownership transferred to Qt.

Sets the child item at ( row , column ) 到 item . This item (the parent item) takes ownership of item . If necessary, the row count and column count are increased to fit the item.

另请参阅 child ().

QStandardItem.setChild ( self , int  arow , QStandardItem   aitem )

aitem argument has it's ownership transferred to Qt.

这是重载函数。

Sets the child at row to item .

QStandardItem.setColumnCount ( self , int  columns )

Sets the number of child item columns to columns . If this is less than columnCount (), the data in the unwanted columns is discarded.

另请参阅 columnCount () 和 setRowCount ().

QStandardItem.setData ( self , QVariant  value , int  role  = Qt.UserRole+1)

Sets the item's data for the given role 到指定 value .

If you subclass QStandardItem and reimplement this function, your reimplementation should call emitDataChanged () if you do not call the base implementation of setData(). This will ensure that e.g. views using the model are notified of the 改变。

注意: The default implementation treats Qt.EditRole and Qt.DisplayRole as referring to the same data.

另请参阅 Qt.ItemDataRole , data (),和 setFlags ().

QStandardItem.setDragEnabled ( self , bool  dragEnabled )

Sets whether the item is drag enabled. If dragEnabled is true, the item can be dragged by the user; otherwise, the user cannot drag the item.

Note that you also need to ensure that item dragging is enabled in the view; see QAbstractItemView.dragEnabled .

另请参阅 isDragEnabled (), setDropEnabled (),和 setFlags ().

QStandardItem.setDropEnabled ( self , bool  dropEnabled )

Sets whether the item is drop enabled. If dropEnabled is true, the item can be used as a drop target; otherwise, it cannot.

Note that you also need to ensure that drops are enabled in the view; see QWidget.acceptDrops (); and that the model supports the desired drop actions; see QAbstractItemModel.supportedDropActions ().

另请参阅 isDropEnabled (), setDragEnabled (),和 setFlags ().

QStandardItem.setEditable ( self , bool  editable )

Sets whether the item is editable. If editable is true, the item can be edited by the user; otherwise, the user cannot edit the item.

How the user can edit items in a view is determined by the view's edit triggers; see QAbstractItemView.editTriggers .

另请参阅 isEditable () 和 setFlags ().

QStandardItem.setEnabled ( self , bool  enabled )

Sets whether the item is enabled. If enabled is true, the item is enabled, meaning that the user can interact with the item; if enabled is false, the user cannot interact with the 项。

This flag takes precedence over the other item flags; e.g. if an item is not enabled, it cannot be selected by the user, even if the Qt.ItemIsSelectable flag has been set.

另请参阅 isEnabled (), Qt.ItemIsEnabled ,和 setFlags ().

QStandardItem.setFlags ( self , Qt.ItemFlags   flags )

Sets the item flags for the item to flags .

The item flags determine how the user can interact with the item. This is often used to disable an item.

另请参阅 flags () and setData ().

QStandardItem.setFont ( self , QFont   afont )

Sets the font used to display the item's text to the given font .

另请参阅 font (), setText (),和 setForeground ().

QStandardItem.setForeground ( self , QBrush   abrush )

Sets the brush used to display the item's foreground (e.g. text) 到给定 brush .

另请参阅 foreground (), setBackground (),和 setFont ().

QStandardItem.setIcon ( self , QIcon   aicon )

Sets the item's icon to the icon 指定。

另请参阅 icon ().

QStandardItem.setRowCount ( self , int  rows )

Sets the number of child item rows to rows . If this is less than rowCount (), the data in the unwanted rows is discarded.

另请参阅 rowCount () 和 setColumnCount ().

QStandardItem.setSelectable ( self , bool  selectable )

Sets whether the item is selectable. If selectable is true, the item can be selected by the user; otherwise, the user cannot select the item.

You can control the selection behavior and mode by manipulating their view properties; see QAbstractItemView.selectionMode and QAbstractItemView.selectionBehavior .

另请参阅 isSelectable () 和 setFlags ().

QStandardItem.setSizeHint ( self , QSize   asizeHint )

Sets the size hint for the item to be size . If no size hint is set, the item delegate will compute the size hint based on the item data.

另请参阅 sizeHint ().

QStandardItem.setStatusTip ( self , QString  astatusTip )

Sets the item's status tip to the string specified by statusTip .

另请参阅 statusTip (), setToolTip (),和 setWhatsThis ().

QStandardItem.setText ( self , QString  atext )

Sets the item's text to the text 指定。

另请参阅 text (), setFont (),和 setForeground ().

QStandardItem.setTextAlignment ( self , Qt.Alignment   atextAlignment )

Sets the text alignment for the item's text to the alignment 指定。

另请参阅 textAlignment ().

QStandardItem.setToolTip ( self , QString  atoolTip )

Sets the item's tooltip to the string specified by toolTip .

另请参阅 toolTip (), setStatusTip (),和 setWhatsThis ().

QStandardItem.setTristate ( self , bool  tristate )

Sets whether the item is tristate. If tristate is true, the item is checkable with three separate states; otherwise, the item is checkable with two states. (Note that this also requires that the item is checkable; see isCheckable ().)

另请参阅 isTristate (), setCheckable (),和 setCheckState ().

QStandardItem.setWhatsThis ( self , QString  awhatsThis )

Sets the item's "What's This?" help to the string specified by whatsThis .

另请参阅 whatsThis (), setStatusTip (),和 setToolTip ().

QSize QStandardItem.sizeHint ( self )

Returns the size hint set for the item, or an invalid QSize if no size hint has been set.

If no size hint has been set, the item delegate will compute the size hint based on the item data.

另请参阅 setSizeHint ().

QStandardItem.sortChildren ( self , int  column , Qt.SortOrder   order  = Qt.AscendingOrder)

Sorts the children of the item using the given order , by the values in the given column .

注意: This function is recursive, therefore it sorts the children of the item, its grandchildren, etc.

另请参阅 operator< ().

QString QStandardItem.statusTip ( self )

Returns the item's status tip.

另请参阅 setStatusTip (), toolTip (),和 whatsThis ().

QStandardItem QStandardItem.takeChild ( self , int  row , int  column  = 0)

QStandardItem result

Removes the child item at ( row , column ) without deleting it, and returns a pointer to the item. If there was no child at the given location, then this function returns 0.

Note that this function, unlike takeRow () 和 takeColumn (), does not affect the dimensions of the child table.

另请参阅 child (), takeRow (),和 takeColumn ().

list-of-QStandardItem QStandardItem.takeColumn ( self , int  column )

list-of-QStandardItem result

移除 column without deleting the column items, and returns a list of pointers to the removed items. For items in the column that have not been set, the corresponding pointers in the list will be 0.

另请参阅 removeColumn (), insertColumn (),和 takeRow ().

list-of-QStandardItem QStandardItem.takeRow ( self , int  row )

list-of-QStandardItem result

移除 row without deleting the row items, and returns a list of pointers to the removed items. For items in the row that have not been set, the corresponding pointers in the list will be 0.

另请参阅 removeRow (), insertRow (),和 takeColumn ().

QString QStandardItem.text ( self )

Returns the item's text. This is the text that's presented to the user in a view.

另请参阅 setText ().

Qt.Alignment QStandardItem.textAlignment ( self )

Returns the text alignment for the item's text.

另请参阅 setTextAlignment ().

QString QStandardItem.toolTip ( self )

Returns the item's tooltip.

另请参阅 setToolTip (), statusTip (),和 whatsThis ().

int QStandardItem.type ( self )

Returns the type of this item. The type is used to distinguish custom items from the base class. When subclassing QStandardItem , you should reimplement this function and return a new value greater than or equal to UserType .

另请参阅 QStandardItem.Type .

QString QStandardItem.whatsThis ( self )

Returns the item's "What's This?" help.

另请参阅 setWhatsThis (), toolTip (),和 statusTip ().

QStandardItem.write ( self , QDataStream   out )

把项写入流 out . Only the data and flags of the item are written, not the child items.

另请参阅 read ().

bool QStandardItem.__ge__ ( self , QStandardItem   other )

bool QStandardItem.__lt__ ( self , QStandardItem   other )