QTableWidgetItem 类提供项为用于 QTableWidget 类。 更多...
头: | #include <QTableWidgetItem> |
CMake: |
find_package(Qt6 COMPONENTS Widgets REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
enum | ItemType { Type, UserType } |
QTableWidgetItem (const QTableWidgetItem & other ) | |
QTableWidgetItem (const QIcon & icon , const QString & text , int type = Type) | |
QTableWidgetItem (const QString & text , int type = Type) | |
QTableWidgetItem (int type = Type) | |
QTableWidgetItem & | operator= (const QTableWidgetItem & other ) |
virtual | ~QTableWidgetItem () |
QBrush | background () const |
Qt::CheckState | checkState () const |
virtual QTableWidgetItem * | clone () const |
int | column () const |
virtual QVariant | data (int role ) const |
Qt::ItemFlags | flags () const |
QFont | font () const |
QBrush | foreground () const |
QIcon | icon () const |
bool | isSelected () const |
virtual void | read (QDataStream & in ) |
int | row () const |
void | setBackground (const QBrush & brush ) |
void | setCheckState (Qt::CheckState state ) |
virtual void | setData (int role , const QVariant & value ) |
void | setFlags (Qt::ItemFlags flags ) |
void | setFont (const QFont & font ) |
void | setForeground (const QBrush & brush ) |
void | setIcon (const QIcon & icon ) |
void | setSelected (bool select ) |
void | setSizeHint (const QSize & size ) |
void | setStatusTip (const QString & statusTip ) |
void | setText (const QString & text ) |
void | setTextAlignment (int alignment ) |
void | setToolTip (const QString & toolTip ) |
void | setWhatsThis (const QString & whatsThis ) |
QSize | sizeHint () const |
QString | statusTip () const |
QTableWidget * | tableWidget () const |
QString | text () const |
int | textAlignment () const |
QString | toolTip () const |
int | type () const |
QString | whatsThis () const |
virtual void | write (QDataStream & out ) const |
virtual bool | operator< (const QTableWidgetItem & other ) const |
QDataStream & | operator<< (QDataStream & out , const QTableWidgetItem & item ) |
QDataStream & | operator>> (QDataStream & in , QTableWidgetItem & item ) |
Table items are used to hold pieces of information for table widgets. Items usually contain text, icons, or checkboxes
The QTableWidgetItem class is a convenience class that replaces the
QTableItem
class in Qt 3. It provides an item for use with the
QTableWidget
类。
Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers:
QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg( pow(row, column+1))); tableWidget->setItem(row, column, newItem);
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 () 采用适当值 (见 Qt::ItemFlags )。可复选项可以被复选和取消复选采用 setCheckState () 函数。相应 checkState () 函数指示项目前是否被复选。
When subclassing QTableWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType .
另请参阅 QTableWidget , 模型/视图编程 , QListWidgetItem ,和 QTreeWidgetItem .
This enum describes the types that are used to describe table widget items.
常量 | 值 | 描述 |
---|---|---|
QTableWidgetItem::Type
|
0
|
The default type for table widget items. |
QTableWidgetItem::UserType
|
1000
|
用于自定义类型的最小值。低于 UserType 的值由 Qt 预留。 |
可以定义新用户类型在 QTableWidgetItem 子类以确保自定义项被特殊对待。
另请参阅 type ().
构造副本为 other 。注意, type () 和 tableWidget () 不拷贝。
此函数是有用的,当重实现 clone ().
Constructs a table item with the given icon and text .
另请参阅 type ().
Constructs a table item with the given text .
另请参阅 type ().
Constructs a table item of the specified type that does not belong to any table.
另请参阅 type ().
赋值 other 的数据和标志到此项。注意 type () 和 tableWidget () 不拷贝。
此函数是有用的,当重实现 clone ().
[virtual]
QTableWidgetItem::
~QTableWidgetItem
()
Destroys the table item.
Returns the brush used to render the item's background.
另请参阅 setBackground () 和 foreground ().
Returns the checked state of the table item.
另请参阅 setCheckState () 和 flags ().
[virtual]
QTableWidgetItem
*QTableWidgetItem::
clone
() const
Creates a copy of the item.
Returns the column of the item in the table. If the item is not in a table, this function will return -1.
另请参阅 row ().
[virtual]
QVariant
QTableWidgetItem::
data
(
int
role
) const
Returns the item's data for the given role .
另请参阅 setData ().
返回用于描述项的标志。这些确定项是否可以被复选、编辑及选择。
另请参阅 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
若项被选中,否则返回
false
.
另请参阅 setSelected ().
[virtual]
void
QTableWidgetItem::
read
(
QDataStream
&
in
)
读取项从流 in .
另请参阅 write ().
Returns the row of the item in the table. If the item is not in a table, this function will return -1.
另请参阅 column ().
Sets the item's background brush to the specified brush 。设置默认构造的笔刷将使视图使用来自样式的默认颜色。
另请参阅 background () 和 setForeground ().
Sets the check state of the table item to be state .
另请参阅 checkState ().
[virtual]
void
QTableWidgetItem::
setData
(
int
role
, const
QVariant
&
value
)
Sets the item's data for the given role 到指定 value .
注意: 默认实现视 Qt::EditRole and Qt::DisplayRole 为引用相同数据。
另请参阅 Qt::ItemDataRole and data ().
将项的标志设为给定 flags . These determine whether the item can be selected or modified.
另请参阅 flags ().
Sets the font used to display the item's text to the given font .
另请参阅 font (), setText (),和 setForeground ().
Sets the item's foreground brush to the specified brush 。设置默认构造的笔刷将使视图使用来自样式的默认颜色。
另请参阅 foreground () 和 setBackground ().
Sets the item's icon to the icon 指定。
另请参阅 icon (), setText (),和 iconSize .
将项的选定状态设为 select .
另请参阅 isSelected ().
Sets the size hint for the table item to be size 。若未设置大小提示或 size 无效,项委托将基于项数据计算大小提示。
另请参阅 sizeHint ().
Sets the status tip for the table item to the text specified by statusTip . QTableWidget 鼠标追踪需要启用为使此特征能工作。
另请参阅 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 () 和 Qt::Alignment .
Sets the item's tooltip to the string specified by toolTip .
另请参阅 toolTip (), setStatusTip (),和 setWhatsThis ().
Sets the item's "What's This?" help to the string specified by whatsThis .
另请参阅 whatsThis (), setStatusTip (),和 setToolTip ().
Returns the size hint set for the table item.
另请参阅 setSizeHint ().
Returns the item's status tip.
另请参阅 setStatusTip ().
Returns the table widget that contains the item.
返回项的文本。
另请参阅 setText ().
Returns the text alignment for the item's text.
另请参阅 setTextAlignment () 和 Qt::Alignment .
Returns the item's tooltip.
另请参阅 setToolTip ().
返回类型被传递给 QTableWidgetItem 构造函数。
Returns the item's "What's This?" help.
另请参阅 setWhatsThis ().
[virtual]
void
QTableWidgetItem::
write
(
QDataStream
&
out
) const
把项写入流 out .
另请参阅 read ().
[virtual]
bool
QTableWidgetItem::
operator<
(const
QTableWidgetItem
&
other
) const
返回
true
if the item is less than the
other
item; otherwise returns false.
Writes the table widget item item 到流 out .
此操作符使用 QTableWidgetItem::write ().
另请参阅 序列化 Qt 数据类型 .
Reads a table widget item from stream in into item .
此操作符使用 QTableWidgetItem::read ().
另请参阅 序列化 Qt 数据类型 .