QStandardItem 类提供的项用于 QStandardItemModel 类。 更多...
头: | #include <QStandardItem> |
CMake: |
find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
enum | ItemType { Type, UserType } |
QStandardItem (int rows , int columns = 1) | |
QStandardItem (const QIcon & icon , const QString & text ) | |
QStandardItem (const QString & text ) | |
QStandardItem () | |
virtual | ~QStandardItem () |
QString | accessibleDescription () const |
QString | accessibleText () const |
void | appendColumn (const QList<QStandardItem *> & 项 ) |
void | appendRow (const QList<QStandardItem *> & 项 ) |
void | appendRow (QStandardItem * item ) |
void | appendRows (const QList<QStandardItem *> & 项 ) |
QBrush | background () const |
Qt::CheckState | checkState () const |
QStandardItem * | child (int row , int column = 0) const |
void | clearData () |
virtual QStandardItem * | clone () const |
int | column () const |
int | columnCount () const |
virtual QVariant | data (int role = Qt::UserRole + 1) const |
Qt::ItemFlags | flags () const |
QFont | font () const |
QBrush | foreground () const |
bool | hasChildren () const |
QIcon | icon () const |
QModelIndex | index () const |
void | insertColumn (int column , const QList<QStandardItem *> & 项 ) |
void | insertColumns (int column , int count ) |
void | insertRow (int row , const QList<QStandardItem *> & 项 ) |
void | insertRow (int row , QStandardItem * item ) |
void | insertRows (int row , const QList<QStandardItem *> & 项 ) |
void | insertRows (int row , int count ) |
bool | isAutoTristate () const |
bool | isCheckable () const |
bool | isDragEnabled () const |
bool | isDropEnabled () const |
bool | isEditable () const |
bool | isEnabled () const |
bool | isSelectable () const |
bool | isUserTristate () const |
QStandardItemModel * | model () const |
virtual void | multiData (QModelRoleDataSpan roleDataSpan ) const |
QStandardItem * | parent () const |
virtual void | read (QDataStream & in ) |
void | removeColumn (int column ) |
void | removeColumns (int column , int count ) |
void | removeRow (int row ) |
void | removeRows (int row , int count ) |
int | row () const |
int | rowCount () const |
void | setAccessibleDescription (const QString & accessibleDescription ) |
void | setAccessibleText (const QString & accessibleText ) |
void | setAutoTristate (bool tristate ) |
void | setBackground (const QBrush & brush ) |
void | setCheckState (Qt::CheckState state ) |
void | setCheckable (bool checkable ) |
void | setChild (int row , int column , QStandardItem * item ) |
void | setChild (int row , QStandardItem * item ) |
void | setColumnCount (int columns ) |
virtual void | setData (const QVariant & value , int role = Qt::UserRole + 1) |
void | setDragEnabled (bool dragEnabled ) |
void | setDropEnabled (bool dropEnabled ) |
void | setEditable (bool editable ) |
void | setEnabled (bool enabled ) |
void | setFlags (Qt::ItemFlags flags ) |
void | setFont (const QFont & font ) |
void | setForeground (const QBrush & brush ) |
void | setIcon (const QIcon & icon ) |
void | setRowCount (int rows ) |
void | setSelectable (bool selectable ) |
void | setSizeHint (const QSize & size ) |
void | setStatusTip (const QString & statusTip ) |
void | setText (const QString & text ) |
void | setTextAlignment (Qt::Alignment alignment ) |
void | setToolTip (const QString & toolTip ) |
void | setUserTristate (bool tristate ) |
void | setWhatsThis (const QString & whatsThis ) |
QSize | sizeHint () const |
void | sortChildren (int column , Qt::SortOrder order = Qt::AscendingOrder) |
QString | statusTip () const |
QStandardItem * | takeChild (int row , int column = 0) |
QList<QStandardItem *> | takeColumn (int column ) |
QList<QStandardItem *> | takeRow (int row ) |
QString | text () const |
Qt::Alignment | textAlignment () const |
QString | toolTip () const |
virtual int | type () const |
QString | whatsThis () const |
virtual void | write (QDataStream & out ) const |
virtual bool | operator< (const QStandardItem & other ) const |
QStandardItem (const QStandardItem & other ) | |
QStandardItem & | operator= (const QStandardItem & other ) |
void | emitDataChanged () |
QDataStream & | operator<< (QDataStream & out , const QStandardItem & item ) |
QDataStream & | operator>> (QDataStream & in , QStandardItem & item ) |
Items usually contain text, icons, or checkboxes.
Each item can have its own background brush which is set with the setBackground () 函数。可以找到当前背景笔刷采用 background (). The text label for each item can be rendered with its own font and brush. These are specified with the setFont () 和 setForeground () 函数,和读取采用 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 () 函数。相应 checkState () 函数指示项目前是否被复选。
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 .
重实现 data () 和 setData () if you want to perform custom handling of data queries and/or control how an item's data is represented.
重实现 clone () if you want QStandardItemModel to be able to create instances of your custom item class on demand (see QStandardItemModel::setItemPrototype ()).
重实现 read () 和 write () if you want to control how items are represented in their serialized form.
重实现 operator< () if you want to control the semantics of item comparison. operator< () determines the sorted order when sorting items with sortChildren () 或采用 QStandardItemModel::sort ().
另请参阅 QStandardItemModel , 项视图方便类 ,和 模型/视图编程 .
This enum describes the types that are used to describe standard items.
常量 | 值 | 描述 |
---|---|---|
QStandardItem::Type
|
0
|
The default type for standard items. |
QStandardItem::UserType
|
1000
|
用于自定义类型的最小值。低于 UserType 的值由 Qt 预留。 |
可以定义新用户类型在 QStandardItem 子类以确保自定义项得到特殊处理;例如,当排序项时。
另请参阅 type ().
[protected]
QStandardItem::
QStandardItem
(const
QStandardItem
&
other
)
构造副本为 other 。注意, model () is not copied.
此函数是有用的,当重实现 clone ().
Constructs an item with rows rows and columns columns of child items.
Constructs an item with the given icon and text .
Constructs an item with the given text .
Constructs an item.
[protected]
QStandardItem
&QStandardItem::
operator=
(const
QStandardItem
&
other
)
赋值 other 的数据和标志到此项。注意 type () 和 model () 不拷贝。
此函数是有用的,当重实现 clone ().
[虚拟]
QStandardItem::
~QStandardItem
()
Destructs the item. This causes the item's children to be destructed as well.
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 () 和 accessibleText ().
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 ().
Appends a column containing 项 . If necessary, the row count is increased to the size of 项 .
另请参阅 insertColumn ().
Appends a row containing 项 . If necessary, the column count is increased to the size of 项 .
另请参阅 insertRow ().
这是重载函数。
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.
Appends rows containing 项 . The column count will not change.
另请参阅 insertRow ().
Returns the brush used to render the item's background.
另请参阅 foreground () 和 setBackground ().
Returns the checked state of the item.
另请参阅 setCheckState () 和 isCheckable ().
Returns the child item at (
row
,
column
) if one has been set; otherwise returns
nullptr
.
另请参阅 setChild (), takeChild (),和 parent ().
[since 5.12]
void
QStandardItem::
clearData
()
Removes all the data from all roles previously set.
该函数在 Qt 5.12 引入。
[虚拟]
QStandardItem
*QStandardItem::
clone
() const
Returns a copy of this item. The item's children are not copied.
当子类化 QStandardItem , you can reimplement this function to provide QStandardItemModel with a factory that it can use to create new items on demand.
另请参阅 QStandardItemModel::setItemPrototype () 和 operator= ().
Returns the column where the item is located in its parent's child table, or -1 if the item has no parent.
Returns the number of child item columns that the item has.
另请参阅 setColumnCount () 和 rowCount ().
[虚拟]
QVariant
QStandardItem::
data
(
int
role
= Qt::UserRole + 1) const
Returns the item's data for the given role ,或无效 QVariant if there is no data for the role.
注意: 默认实现视 Qt::EditRole and Qt::DisplayRole 为引用相同数据。
另请参阅 setData ().
[protected]
void
QStandardItem::
emitDataChanged
()
促使关联此项的模型发射 dataChanged () 信号对于此项。
通常只需调用此函数若有子类化 QStandardItem 并重实现 data () 和/或 setData ().
另请参阅 setData ().
Returns the item flags for the item.
The item flags determine how the user can interact with the item.
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 ().
Returns the font used to render the item's text.
另请参阅 setFont ().
Returns the brush used to render the item's foreground (e.g. text).
另请参阅 setForeground () 和 background ().
返回
true
if this item has any children; otherwise returns
false
.
另请参阅 rowCount (), columnCount (),和 child ().
返回项图标。
返回 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 () 和 QStandardItemModel::itemFromIndex ().
Inserts a column at column 包含 项 . If necessary, the row count is increased to the size of 项 .
另请参阅 insertColumns () 和 insertRow ().
插入 count columns of child items at column column .
另请参阅 insertColumn () 和 insertRows ().
Inserts a row at row 包含 项 . If necessary, the column count is increased to the size of 项 .
另请参阅 insertRows () 和 insertColumn ().
这是重载函数。
Inserts a row at row 包含 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.
插入 项 at row . The column count won't be changed.
另请参阅 insertRow () 和 insertColumn ().
插入 count rows of child items at row row .
另请参阅 insertRow () 和 insertColumns ().
[since 5.6]
bool
QStandardItem::
isAutoTristate
() const
Returns whether the item is tristate and is controlled by QTreeWidget .
默认值为 false。
该函数在 Qt 5.6 引入。
另请参阅 setAutoTristate (), isCheckable (),和 checkState ().
Returns whether the item is user-checkable.
默认值为 false。
另请参阅 setCheckable (), checkState (), isUserTristate (),和 isAutoTristate ().
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 ().
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 ().
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 ().
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 ().
Returns whether the item is selectable by the user.
默认值为 true。
另请参阅 setSelectable () 和 flags ().
[since 5.6]
bool
QStandardItem::
isUserTristate
() const
Returns whether the item is tristate; that is, if it's checkable with three separate states and the user can cycle through all three states.
默认值为 false。
该函数在 Qt 5.6 引入。
另请参阅 setUserTristate (), isCheckable (),和 checkState ().
返回 QStandardItemModel that this item belongs to.
If the item is not a child of another item that belongs to the model, this function returns
nullptr
.
另请参阅 index ().
[virtual, since 6.0]
void
QStandardItem::
multiData
(
QModelRoleDataSpan
roleDataSpan
) const
填充 roleDataSpan span with the data from this item.
默认实现只需调用 data () for each role in the span.
该函数在 Qt 6.0 引入。
另请参阅 data ().
Returns the item's parent item, or
nullptr
if the item has no parent.
注意:
For toplevel items parent() returns
nullptr
. To receive toplevel item's parent use
QStandardItemModel::invisibleRootItem
() 代替。
另请参阅 child () 和 QStandardItemModel::invisibleRootItem ().
[虚拟]
void
QStandardItem::
read
(
QDataStream
&
in
)
读取项从流 in . Only the data and flags of the item are read, not the child items.
另请参阅 write ().
移除给定 column . The items that were in the column are deleted.
另请参阅 takeColumn (), removeColumns (),和 removeRow ().
移除 count columns at column column . The items that were in those columns are deleted.
另请参阅 removeColumn () 和 removeRows ().
移除给定 row . The items that were in the row are deleted.
另请参阅 takeRow (), removeRows (),和 removeColumn ().
移除 count rows at row row . The items that were in those rows are deleted.
另请参阅 removeRow () 和 removeColumn ().
Returns the row where the item is located in its parent's child table, or -1 if the item has no parent.
Returns the number of child item rows that the item has.
另请参阅 setRowCount () 和 columnCount ().
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 () 和 setAccessibleText ().
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 ().
[since 5.6]
void
QStandardItem::
setAutoTristate
(
bool
tristate
)
Determines that the item is tristate and controlled by
QTreeWidget
if
tristate
is
true
. This enables automatic management of the state of parent items in
QTreeWidget
(复选若所有子级被复选,取消复选若所有子级被取消复选,或部分复选若仅某些子级被复选)。
该函数在 Qt 5.6 引入。
另请参阅 isAutoTristate (), setCheckable (),和 setCheckState ().
Sets the item's background brush to the specified brush .
另请参阅 background () 和 setForeground ().
Sets the check state of the item to be state .
另请参阅 checkState () 和 setCheckable ().
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 (), setUserTristate (),和 setAutoTristate ().
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.
注意:
传递
nullptr
as
item
removes the item.
另请参阅 child ().
这是重载函数。
Sets the child at row to item .
Sets the number of child item columns to columns 。若这小于 columnCount (),不想要列中的数据被丢弃。
另请参阅 columnCount () 和 setRowCount ().
[虚拟]
void
QStandardItem::
setData
(const
QVariant
&
value
,
int
role
= Qt::UserRole + 1)
Sets the item's data for the given role 到指定 value .
若子类 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 changes.
注意: 默认实现视 Qt::EditRole and Qt::DisplayRole 为引用相同数据。
另请参阅 Qt::ItemDataRole , data (),和 setFlags ().
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 ().
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 ().
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 ().
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 item.
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 ().
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.
Sets the font used to display the item's text to the given font .
另请参阅 font (), setText (),和 setForeground ().
Sets the brush used to display the item's foreground (e.g. text) to the given brush .
另请参阅 foreground (), setBackground (),和 setFont ().
Sets the item's icon to the icon 指定。
另请参阅 icon ().
Sets the number of child item rows to rows 。若这小于 rowCount (),丢弃不想要行中的数据。
另请参阅 rowCount () 和 setColumnCount ().
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 ().
Sets the size hint for the item to be size 。若未设置大小提示,项委托将基于项数据计算大小提示。
另请参阅 sizeHint ().
Sets the item's status tip to the string specified by statusTip .
另请参阅 statusTip (), setToolTip (),和 setWhatsThis ().
Sets the item's text to the text 指定。
另请参阅 text (), setFont (),和 setForeground ().
Sets the text alignment for the item's text to the alignment 指定。
另请参阅 textAlignment ().
Sets the item's tooltip to the string specified by toolTip .
另请参阅 toolTip (), setStatusTip (),和 setWhatsThis ().
[since 5.6]
void
QStandardItem::
setUserTristate
(
bool
tristate
)
Sets whether the item is tristate and controlled by the user. If tristate is true, the user can cycle through three separate states; otherwise, the item is checkable with two states. (Note that this also requires that the item is checkable; see isCheckable ().)
该函数在 Qt 5.6 引入。
另请参阅 isUserTristate (), setCheckable (),和 setCheckState ().
Sets the item's "What's This?" help to the string specified by whatsThis .
另请参阅 whatsThis (), setStatusTip (),和 setToolTip ().
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 ().
排序项的子级使用给定 order ,通过值在给定 column .
注意: This function is recursive, therefore it sorts the children of the item, its grandchildren, etc.
另请参阅 operator< ().
Returns the item's status tip.
另请参阅 setStatusTip (), toolTip (),和 whatsThis ().
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
nullptr
.
Note that this function, unlike takeRow () 和 takeColumn (), does not affect the dimensions of the child table.
另请参阅 child (), takeRow (),和 takeColumn ().
移除
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
nullptr
.
另请参阅 removeColumn (), insertColumn (),和 takeRow ().
移除
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
nullptr
.
另请参阅 removeRow (), insertRow (),和 takeColumn ().
Returns the item's text. This is the text that's presented to the user in a view.
另请参阅 setText ().
Returns the text alignment for the item's text.
另请参阅 setTextAlignment ().
Returns the item's tooltip.
另请参阅 setToolTip (), statusTip (),和 whatsThis ().
[虚拟]
int
QStandardItem::
type
() const
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 .
Returns the item's "What's This?" help.
另请参阅 setWhatsThis (), toolTip (),和 statusTip ().
[虚拟]
void
QStandardItem::
write
(
QDataStream
&
out
) const
把项写入流 out . Only the data and flags of the item are written, not the child items.
另请参阅 read ().
[虚拟]
bool
QStandardItem::
operator<
(const
QStandardItem
&
other
) const
返回
true
if this item is less than
other
;否则返回
false
.
The default implementation uses the data for the item's sort role (see QStandardItemModel::sortRole ) to perform the comparison if the item belongs to a model; otherwise, the data for the item's Qt::DisplayRole ( text ()) is used to perform the comparison.
sortChildren () 和 QStandardItemModel::sort () use this function when sorting items. If you want custom sorting, you can subclass QStandardItem and reimplement this function.
写入 QStandardItem item 到流 out .
此操作符使用 QStandardItem::write ().
另请参阅 序列化 Qt 数据类型 .
读取 QStandardItem from stream in into item .
此操作符使用 QStandardItem::read ().
另请参阅 序列化 Qt 数据类型 .