IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QTableWidgetItem Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QTableWidgetItem Class

  • Header: QTableWidgetItem

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Widgets)

    target_link_libraries(mytarget PRIVATE Qt6::Widgets)

  • qmake: QT += widgets

  • Group: QTableWidgetItem is part of model-view

Detailed Description

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 class.

Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers:

 
Sélectionnez
    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() 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() and setForeground() functions, and read with font() and 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() with the appropriate value (see Qt::ItemFlags). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.

Subclassing

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.

See Also

Member Type Documentation

 

enum QTableWidgetItem::ItemType

This enum describes the types that are used to describe table widget items.

Constant

Value

Description

QTableWidgetItem::Type

0

The default type for table widget items.

QTableWidgetItem::UserType

1000

The minimum value for custom types. Values below UserType are reserved by Qt.

You can define new user types in QTableWidgetItem subclasses to ensure that custom items are treated specially.

See Also

See also type()

Member Function Documentation

 

[explicit] QTableWidgetItem::QTableWidgetItem(int type = Type)

Constructs a table item of the specified type that does not belong to any table.

See Also

See also type()

[explicit] QTableWidgetItem::QTableWidgetItem(const QString &text, int type = Type)

Constructs a table item with the given text.

See Also

See also type()

[explicit] QTableWidgetItem::QTableWidgetItem(const QIcon &icon, const QString &text, int type = Type)

Constructs a table item with the given icon and text.

See Also

See also type()

QTableWidgetItem::QTableWidgetItem(const QTableWidgetItem &other)

Constructs a copy of other. Note that type() and tableWidget() are not copied.

This function is useful when reimplementing clone().

See Also

See also data(), flags()

[virtual] QTableWidgetItem::~QTableWidgetItem()

Destroys the table item.

QBrush QTableWidgetItem::background() const

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

See Also

See also setBackground(), foreground()

Qt::CheckState QTableWidgetItem::checkState() const

Returns the checked state of the table item.

See Also

See also setCheckState(), flags()

[virtual] QTableWidgetItem *QTableWidgetItem::clone() const

Creates a copy of the item.

int QTableWidgetItem::column() const

Returns the column of the item in the table. If the item is not in a table, this function will return -1.

See Also

See also row()

[virtual] QVariant QTableWidgetItem::data(int role) const

Returns the item's data for the given role.

See Also

See also setData()

Qt::ItemFlags QTableWidgetItem::flags() const

Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.

See Also

See also setFlags()

QFont QTableWidgetItem::font() const

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

See Also

See also setFont()

QBrush QTableWidgetItem::foreground() const

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

See Also

See also setForeground(), background()

QIcon QTableWidgetItem::icon() const

Returns the item's icon.

See Also

See also setIcon(), iconSize

bool QTableWidgetItem::isSelected() const

Returns true if the item is selected, otherwise returns false.

See Also

See also setSelected()

[virtual] void QTableWidgetItem::read(QDataStream &in)

Reads the item from stream in.

See Also

See also write()

int QTableWidgetItem::row() const

Returns the row of the item in the table. If the item is not in a table, this function will return -1.

See Also

See also column()

void QTableWidgetItem::setBackground(const QBrush &brush)

Sets the item's background brush to the specified brush. Setting a default-constructed brush will let the view use the default color from the style.

See Also

See also background(), setForeground()

void QTableWidgetItem::setCheckState(Qt::CheckState state)

Sets the check state of the table item to be state.

See Also

See also checkState()

[virtual] void QTableWidgetItem::setData(int role, const QVariant &value)

Sets the item's data for the given role to the specified value.

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

See Also

See also Qt::ItemDataRole, data()

void QTableWidgetItem::setFlags(Qt::ItemFlags flags)

Sets the flags for the item to the given flags. These determine whether the item can be selected or modified.

See Also

See also flags()

void QTableWidgetItem::setFont(const QFont &font)

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

See Also

See also font(), setText(), setForeground()

void QTableWidgetItem::setForeground(const QBrush &brush)

Sets the item's foreground brush to the specified brush. Setting a default-constructed brush will let the view use the default color from the style.

See Also

See also foreground(), setBackground()

void QTableWidgetItem::setIcon(const QIcon &icon)

Sets the item's icon to the icon specified.

See Also

See also icon(), setText(), iconSize

void QTableWidgetItem::setSelected(bool select)

Sets the selected state of the item to select.

See Also

See also isSelected()

void QTableWidgetItem::setSizeHint(const QSize &size)

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

See Also

See also sizeHint()

void QTableWidgetItem::setStatusTip(const QString &statusTip)

Sets the status tip for the table item to the text specified by statusTip. QTableWidget mouse tracking needs to be enabled for this feature to work.

See Also

See also statusTip(), setToolTip(), setWhatsThis()

void QTableWidgetItem::setText(const QString &text)

Sets the item's text to the text specified.

See Also

See also text(), setFont(), setForeground()

[since 6.4] void QTableWidgetItem::setTextAlignment(Qt::Alignment alignment)

Sets the text alignment for the item's text to the alignment specified.

This function was introduced in Qt 6.4.

void QTableWidgetItem::setToolTip(const QString &toolTip)

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

See Also

See also toolTip(), setStatusTip(), setWhatsThis()

void QTableWidgetItem::setWhatsThis(const QString &whatsThis)

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

See Also

See also whatsThis(), setStatusTip(), setToolTip()

QSize QTableWidgetItem::sizeHint() const

Returns the size hint set for the table item.

See Also

See also setSizeHint()

QString QTableWidgetItem::statusTip() const

Returns the item's status tip.

See Also

See also setStatusTip()

QTableWidget *QTableWidgetItem::tableWidget() const

Returns the table widget that contains the item.

QString QTableWidgetItem::text() const

Returns the item's text.

See Also

See also setText()

int QTableWidgetItem::textAlignment() const

Returns the text alignment for the item's text.

This function returns an int for historical reasons. It will be corrected to return Qt::Alignment in Qt 7.

See Also

QString QTableWidgetItem::toolTip() const

Returns the item's tooltip.

See Also

See also setToolTip()

int QTableWidgetItem::type() const

Returns the type passed to the QTableWidgetItem constructor.

QString QTableWidgetItem::whatsThis() const

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

See Also

See also setWhatsThis()

[virtual] void QTableWidgetItem::write(QDataStream &out) const

Writes the item to stream out.

See Also

See also read()

[virtual] bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const

Returns true if the item is less than the other item; otherwise returns false.

QTableWidgetItem &QTableWidgetItem::operator=(const QTableWidgetItem &other)

Assigns other's data and flags to this item. Note that type() and tableWidget() are not copied.

This function is useful when reimplementing clone().

See Also

See also data(), flags()

Related Non-Members

 

QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item)

Writes the table widget item item to stream out.

This operator uses QTableWidgetItem::write().

See Also

QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item)

Reads a table widget item from stream in into item.

This operator uses QTableWidgetItem::read().

See Also

Obsolete Members for QTableWidgetItem

The following members of class QTableWidgetItem are deprecated. We strongly advise against using them in new code.

Obsolete Member Function Documentation

 
void QTableWidgetItem::setTextAlignment(int alignment)

This function is deprecated. We strongly advise against using it in new code.

Use the overload that takes a Qt::Alignment argument.

Sets the text alignment for the item's text to the alignment specified.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+