QListWidgetItem Class
The QListWidgetItem class is a row of a QListWidget. More…
| Header | #include <QListWidgetItem> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
List of all members, including inherited members
Public Functions
| QListWidgetItem() | |
| QListWidgetItem(const QString &text) | |
| QListWidgetItem(const QString &text, QListWidget *listWidget) | |
| virtual | ~QListWidgetItem() |
| QListWidget * | listWidget() 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 and add it to a list, which takes it over:
QListWidgetItem *item = new QListWidgetItem("Inbox");
item->setToolTip("Mail that has not been sorted");
list->addItem(item);
Deleting an item takes it out of its list.
See also QListWidget.
Differences from Qt
An item holds a text, not a QVariant: there is no data(), setData(), setIcon(), setCheckState() or setSizeHint(), no setHidden(), and no clone(). An item cannot be edited, so there is no ItemIsEditable flag. An item cannot be copied.
Member Function Documentation
QListWidgetItem::QListWidgetItem()
Constructs an item with no text.
QListWidgetItem::QListWidgetItem(const QString &text)
Constructs an item with the given text.
QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *listWidget)
Constructs an item with the given text and adds it at the end of listWidget.
QListWidgetItem::~QListWidgetItem()
Destroys the item, and removes it from its list.
QBrush QListWidgetItem::background() const
Returns the brush that fills the row. A brush with no style (the default) leaves it to the list.
See also setBackground().
Qt::ItemFlags QListWidgetItem::flags() const
Returns what the user can do with the item. The default is that it is enabled and selectable.
See also setFlags().
QFont QListWidgetItem::font() const
Returns the font of the text: the one that was set, or the font of the list.
See also setFont().
QBrush QListWidgetItem::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 QListWidgetItem::isSelected() const
Returns whether the item is selected.
See also setSelected().
QListWidget * QListWidgetItem::listWidget() const
Returns the list that has the item, or nullptr if it is in none.
void QListWidgetItem::setBackground(const QBrush &brush)
Sets the brush that fills the row to brush. Only its color is used.
See also background().
void QListWidgetItem::setFlags(Qt::ItemFlags flags)
Sets what the user can do with the item to flags. An item that is not enabled is drawn in the disabled colors, and the user cannot select it or make it the current item.
See also flags().
void QListWidgetItem::setFont(const QFont &font)
Sets the font of the text to font.
See also font().
void QListWidgetItem::setForeground(const QBrush &brush)
Sets the brush of the text to brush. Only its color is used.
See also foreground().
void QListWidgetItem::setSelected(bool select)
Selects the item if select is true, or deselects it. In a list that allows one selected item, selecting an item deselects the one that was selected. It does nothing for an item that is in no list, that cannot be selected, or in a list with no selection.
See also isSelected().
void QListWidgetItem::setText(const QString &text)
Sets the text of the item to text.
See also text().
void QListWidgetItem::setTextAlignment(Qt::Alignment alignment)
Sets how the text is placed in the row to alignment.
See also textAlignment().
void QListWidgetItem::setToolTip(const QString &toolTip)
Sets the tool tip of the item to toolTip. Without one, the item shows the tool tip of the list.
See also toolTip().
QString QListWidgetItem::text() const
Returns the text of the item.
See also setText().
Qt::Alignment QListWidgetItem::textAlignment() const
Returns how the text is placed in the row. The default is Qt::AlignLeft | Qt::AlignVCenter.
See also setTextAlignment().
QString QListWidgetItem::toolTip() const
Returns the tool tip of the item, which the list shows when the mouse rests over the item.
See also setToolTip().