QTableWidgetItem Class
The QTableWidgetItem class is a cell of a QTableWidget. More…
| Header | #include <QTableWidgetItem> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
List of all members, including inherited members
Public Functions
| QTableWidgetItem() | |
| QTableWidgetItem(const QString &text) | |
| virtual | ~QTableWidgetItem() |
| QTableWidget * | tableWidget() const |
| int | row() const |
| int | column() const |
| QString | text() const |
| void | setText(const QString &text) |
| QString | toolTip() const |
| void | setToolTip(const QString &toolTip) |
| Qt::Alignment | textAlignment() const |
| void | setTextAlignment(Qt::Alignment alignment) |
| QBrush | foreground() const |
| void | setForeground(const QBrush &brush) |
| QBrush | background() const |
| void | setBackground(const QBrush &brush) |
| QFont | font() const |
| void | setFont(const QFont &font) |
| Qt::ItemFlags | flags() const |
| void | setFlags(Qt::ItemFlags flags) |
| bool | isSelected() const |
| void | setSelected(bool select) |
Detailed Description
An item has a text, and how it is drawn: its alignment, colors and font. Create an item, set what it should look like, and give it to a table with QTableWidget::setItem(), which takes it over:
QTableWidgetItem *name = new QTableWidgetItem("Bruce");
name->setForeground(QBrush(QColor(0, 90, 160)));
name->setToolTip("The name of the user");
table->setItem(0, 0, name);
Deleting an item takes it out of its table.
See also QTableWidget.
Differences from Qt
An item holds a text, not a QVariant: there is no data(), setData(), setCheckState(), setIcon() or setSizeHint(), and no type() or clone(). An item cannot be edited, so there is no ItemIsEditable flag. The copy of an item is not allowed.
Member Function Documentation
QTableWidgetItem::QTableWidgetItem()
Constructs an item with no text.
QTableWidgetItem::QTableWidgetItem(const QString &text)
Constructs an item with the given text.
QTableWidgetItem::~QTableWidgetItem()
Destroys the item, and removes it from its table.
QBrush QTableWidgetItem::background() const
Returns the brush that fills the cell. A brush with no style (the default) leaves it to the table.
See also setBackground().
int QTableWidgetItem::column() const
Returns the column of the item in its table, or -1 if it is in none.
See also row().
Qt::ItemFlags QTableWidgetItem::flags() const
Returns what the user can do with the item. The default is that it is enabled and selectable.
See also setFlags().
QFont QTableWidgetItem::font() const
Returns the font of the text: the one that was set, or the font of the table.
See also setFont().
QBrush QTableWidgetItem::foreground() const
Returns the brush of the text. A brush with no style (the default) stands for the text color of the palette.
See also setForeground().
bool QTableWidgetItem::isSelected() const
Returns whether the item is selected. A table has one selected cell, its current cell.
See also setSelected().
int QTableWidgetItem::row() const
Returns the row of the item in its table, or -1 if it is in none.
See also column().
void QTableWidgetItem::setBackground(const QBrush &brush)
Sets the brush that fills the cell to brush. Only its color is used.
See also background().
void QTableWidgetItem::setFlags(Qt::ItemFlags flags)
Sets what the user can do with the item to flags.
See also flags().
void QTableWidgetItem::setFont(const QFont &font)
Sets the font of the text to font.
See also font().
void QTableWidgetItem::setForeground(const QBrush &brush)
Sets the brush of the text to brush. Only its color is used.
See also foreground().
void QTableWidgetItem::setSelected(bool select)
Selects the item if select is true, which makes it the current item of the table; otherwise clears the selection if the item was selected.
See also isSelected().
void QTableWidgetItem::setText(const QString &text)
Sets the text of the item to text.
See also text().
void QTableWidgetItem::setTextAlignment(Qt::Alignment alignment)
Sets how the text is placed in the cell to alignment.
See also textAlignment().
void QTableWidgetItem::setToolTip(const QString &toolTip)
Sets the tool tip of the item to toolTip. Without one, the cell shows the tool tip of the table.
See also toolTip().
QTableWidget * QTableWidgetItem::tableWidget() const
Returns the table that has the item, or nullptr if it is in none.
QString QTableWidgetItem::text() const
Returns the text of the item.
See also setText().
Qt::Alignment QTableWidgetItem::textAlignment() const
Returns how the text is placed in the cell. The default is Qt::AlignLeft | Qt::AlignVCenter.
See also setTextAlignment().
QString QTableWidgetItem::toolTip() const
Returns the tool tip of the item, which the table shows when the mouse rests over the cell.
See also setToolTip().