QListViewItem(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

✨ QListViewItem ✨

okay bestie, this is the Qt manual page QListViewItem(3qt) and it is A LOT, so buckle up πŸ’–


🌸 NAME 🌸

QListViewItem β€” it implements a list view item. that's the whole vibe. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <qlistview.h>

so like, it Inherits Qt. and it gets Inherited by QCheckListItem 🧬 (family tree slay).

πŸ‘‘ Public Members πŸ‘‘

QListViewItem ( QListView * parent )
QListViewItem ( QListViewItem * parent )
QListViewItem ( QListView * parent, QListViewItem * after )
QListViewItem ( QListViewItem * parent, QListViewItem * after )
QListViewItem ( QListView * parent, QString label1, QString label2 =
    QString::null, QString label3 = QString::null, QString label4 =
    QString::null, QString label5 = QString::null, QString label6 =
    QString::null, QString label7 = QString::null, QString label8 =
    QString::null )
QListViewItem ( QListViewItem * parent, QString label1, QString label2 =
    QString::null, QString label3 = QString::null, QString label4 =
    QString::null, QString label5 = QString::null, QString label6 =
    QString::null, QString label7 = QString::null, QString label8 =
    QString::null )
QListViewItem ( QListView * parent, QListViewItem * after, QString
    label1, QString label2 = QString::null, QString label3 =
    QString::null, QString label4 = QString::null, QString label5 =
    QString::null, QString label6 = QString::null, QString label7 =
    QString::null, QString label8 = QString::null )
QListViewItem ( QListViewItem * parent, QListViewItem * after, QString
    label1, QString label2 = QString::null, QString label3 =
    QString::null, QString label4 = QString::null, QString label5 =
    QString::null, QString label6 = QString::null, QString label7 =
    QString::null, QString label8 = QString::null )
virtual ~QListViewItem ()
virtual void insertItem ( QListViewItem * newChild )
virtual void takeItem ( QListViewItem * item )
virtual void removeItem ( QListViewItem * item )  (obsolete)
int height () const
virtual void invalidateHeight ()
int totalHeight () const
virtual int width ( const QFontMetrics & fm, const QListView * lv, int c
    ) const
void widthChanged ( int c = -1 ) const
int depth () const
virtual void setText ( int column, const QString & text )
virtual QString text ( int column ) const
virtual void setPixmap ( int column, const QPixmap & pm )
virtual const QPixmap * pixmap ( int column ) const
virtual QString key ( int column, bool ascending ) const
virtual int compare ( QListViewItem * i, int col, bool ascending ) const
virtual void sortChildItems ( int column, bool ascending )
int childCount () const
bool isOpen () const
virtual void setOpen ( bool o )
virtual void setup ()
virtual void setSelected ( bool s )
bool isSelected () const
virtual void paintCell ( QPainter * p, const QColorGroup & cg, int
    column, int width, int align )
virtual void paintBranches ( QPainter * p, const QColorGroup & cg, int
    w, int y, int h )
virtual void paintFocus ( QPainter * p, const QColorGroup & cg, const
    QRect & r )
QListViewItem * firstChild () const
QListViewItem * nextSibling () const
QListViewItem * parent () const
QListViewItem * itemAbove ()
QListViewItem * itemBelow ()
int itemPos () const
QListView * listView () const
virtual void setSelectable ( bool enable )
bool isSelectable () const
virtual void setExpandable ( bool enable )
bool isExpandable () const
void repaint () const
virtual void sort ()
void moveItem ( QListViewItem * after )
virtual void setDragEnabled ( bool allow )
virtual void setDropEnabled ( bool allow )
bool dragEnabled () const
bool dropEnabled () const
virtual bool acceptDrop ( const QMimeSource * mime ) const
void setVisible ( bool b )
bool isVisible () const
virtual void setRenameEnabled ( int col, bool b )
bool renameEnabled ( int col ) const
virtual void startRename ( int col )
virtual void setEnabled ( bool b )
bool isEnabled () const
virtual int rtti () const
virtual void setMultiLinesEnabled ( bool b )
bool multiLinesEnabled () const

πŸ”’ Protected Members πŸ”’

virtual void enforceSortOrder () const
virtual void setHeight ( int height )
virtual void activate ()
bool activatedPos ( QPoint & pos )
virtual void dropped ( QDropEvent * e )
virtual void dragEntered ()
virtual void dragLeft ()
virtual void okRename ( int col )
virtual void cancelRename ( int col )

πŸ’œ DESCRIPTION πŸ’œ

so the QListViewItem class implements a list view item. that's it, that's the thesis πŸŽ€

a list view item is a multi-column object that's capable of displaying itself in a QListView. multi-column?? she contains multitudes, periodt.

the easiest way to use QListViewItem is to construct one with a few constant strings, and either a QListView or another QListViewItem as parent. like:

(void) new QListViewItem( listView, "Column 1", "Column 2" );
(void) new QListViewItem( listView->firstChild(), "A", "B", "C" );

we've discarded the pointers to the items since we can still access them via their parent listView. by default, QListView sorts its items; this can be switched off with QListView::setSorting(-1) ✨

the parent must be another QListViewItem or a QListView. if the parent is a QListView, the item becomes a top-level item within that QListView. if the parent is another QListViewItem, the item becomes a child of that list view item. no in-between, no ambiguity, we love a clear boundary 🫢

if you keep the pointer, you can set or change the texts using setText(), add pixmaps using setPixmap(), change its mode using setSelectable(), setSelected(), setOpen() and setExpandable(). you'll also be able to change its height using setHeight(), and traverse its sub-items. and honestly? you don't even have to keep the pointer, because you can get a pointer to any QListViewItem in a QListView using QListView::selectedItem(), QListView::currentItem(), QListView::firstChild(), QListView::lastItem() and QListView::findItem(). the list view always has your back πŸ’…

if you call delete on a list view item, it will be deleted as expected, and as usual for QObjects, if it has any child items (to any depth), all these will be deleted too. so like… be normal about it 😭

QCheckListItems are list view items that have a checkbox or radio button and can be used in place of plain QListViewItems. cute AND functional.

you can traverse the tree as if it were a doubly-linked list using itemAbove() and itemBelow(); they return pointers to the items directly above and below this item on the screen (even if none of them are actually visible at the moment). the way that works even when nothing's visible?? iconic.

here's how to traverse all of an item's children (but not its children's children, etc.). example:

QListViewItem * myChild = myItem->firstChild();
while( myChild ) {
    doSomething( myChild );
    myChild = myChild->nextSibling();
}

if you want to iterate over every item, to any level of depth use an iterator. to iterate over the entire tree, initialize the iterator with the list view itself; to iterate starting from a particular item, initialize the iterator with the item:

QListViewItemIterator it( listview );
while ( it.current() ) {
    QListViewItem *item = it.current();
    doSomething( item );
    ++it;
}

note that the order of the children will change when the sorting order changes and is undefined if the items are not visible. you can, however, call enforceSortOrder() at any time; QListView will always call it before it needs to show an item. so like, it's chaotic but it's managed chaos 🌈

many programs will need to reimplement QListViewItem. the most commonly reimplemented functions are: <center>.nf </center>

okay ngl bestie, the original page literally has that <center>.nf </center> artifact sitting right there where the list should be πŸ™ˆ i'm not making it up, i'm just reporting what's on the page.

some subclasses call setExpandable(TRUE) even when they have no children, and populate themselves when setup() or setOpen(TRUE) is called. the dirview/dirview.cpp example program uses this technique to start up quickly: the files and subdirectories in a directory aren't inserted into the tree until they're actually needed. lazy loading before lazy loading was cool, she ate πŸ”₯

[Image Omitted]

See also QCheckListItem, QListView, and Advanced Widgets.


πŸ“– MEMBER FUNCTION DOCUMENTATION πŸ“–

🍼 QListViewItem::QListViewItem ( QListView * parent )

constructs a new top-level list view item in the QListView parent. boom, top level, main character energy πŸ‘‘

🍼 QListViewItem::QListViewItem ( QListViewItem * parent )

constructs a new list view item that is a child of parent and first in the parent's list of children. first!! πŸ₯‡

🍼 QListViewItem::QListViewItem ( QListView * parent, QListViewItem * after )

constructs an empty list view item that is a child of parent and is after item after in the parent's list of children. since parent is a QListView the item will be a top-level item.

🍼 QListViewItem::QListViewItem ( QListViewItem * parent, QListViewItem * after )

constructs an empty list view item that is a child of parent and is after item after in the parent's list of children.

🍼 QListViewItem::QListViewItem ( QListView * parent, QString label1, QString label2 = QString::null, QString label3 = QString::null, QString label4 = QString::null, QString label5 = QString::null, QString label6 = QString::null, QString label7 = QString::null, QString label8 = QString::null )

constructs a new top-level list view item in the QListView parent, with up to eight constant strings, label1, label2, label3, label4, label5, label6, label7 and label8 defining its columns' contents.

See also setText().

🍼 QListViewItem::QListViewItem ( QListViewItem * parent, QString label1, QString label2 = QString::null, QString label3 = QString::null, QString label4 = QString::null, QString label5 = QString::null, QString label6 = QString::null, QString label7 = QString::null, QString label8 = QString::null )

constructs a new list view item as a child of the QListViewItem parent with up to eight constant strings, label1, label2, label3, label4, label5, label6, label7 and label8 as columns' contents.

See also setText().

🍼 QListViewItem::QListViewItem ( QListView * parent, QListViewItem * after, QString label1, QString label2 = QString::null, QString label3 = QString::null, QString label4 = QString::null, QString label5 = QString::null, QString label6 = QString::null, QString label7 = QString::null, QString label8 = QString::null )

constructs a new list view item in the QListView parent that is included after item after and that has up to eight column texts, label1, label2, label3, label4, label5, label6, label7 and label8.

⚠️ note that the order is changed according to QListViewItem::key() unless the list view's sorting is disabled using QListView::setSorting(-1). so if your ordering looks cursed, that's why bestie 😭

See also setText().

✨ QListViewItem::QListViewItem β€” the parent + after + labels constructor ✨

QListViewItem::QListViewItem ( QListViewItem * parent, QListViewItem * after,
       QString label1, QString label2 = QString::null, QString label3 =
       QString::null, QString label4 = QString::null, QString label5 =
       QString::null, QString label6 = QString::null, QString label7 =
       QString::null, QString label8 = QString::null )

Okay bestie, this one builds a brand-new list view item as a child of the QListViewItem called parent. It gets tucked in right after after and can hold up to eight strings β€” label1, label2, label3, label4, label5, label6, label7, and label8 β€” as column entries. πŸ’…

Heads up: the order can get shuffled according to QListViewItem::key() unless the list view's sorting is turned off with QListView::setSorting(-1). So don't be shocked if your labels start moving around. 😭

See also setText().


πŸ’€ QListViewItem::~QListViewItem () [virtual] πŸ’€

Destroys the item, deletes all its children, and frees up all allocated resources. It's giving cleanup era. 🧹✨


πŸ¦‹ bool QListViewItem::acceptDrop ( const QMimeSource * mime ) const [virtual] πŸ¦‹

Returns TRUE if the item can accept drops of type QMimeSource mime; otherwise returns FALSE.

The default implementation does nothing and returns FALSE. A subclass must reimplement this to accept drops. So if you want drop action, you gotta do the work, bestie. πŸ’ͺ


🌸 void QListViewItem::activate () [virtual protected] 🌸

This virtual function is called whenever the user presses the mouse on this item or presses Space on it. Basically the item's main character moment. πŸ‘‘

See also activatedPos().

Reimplemented in QCheckListItem.


πŸŽ€ bool QListViewItem::activatedPos ( QPoint & pos ) [protected] πŸŽ€

When called from a reimplementation of activate(), this function gives information on how the item was activated. Otherwise the behavior is undefined. (So don't call it random, okay? πŸ™ˆ)

If activate() was caused by a mouse press, the function sets pos to where the user clicked and returns TRUE; otherwise it returns FALSE and does not change pos.

pos is relative to the top-left corner of this item.

Warning: We recommend that you ignore this function; it is scheduled to become obsolete.

See also activate().


πŸ’œ void QListViewItem::cancelRename ( int col ) [virtual protected] πŸ’œ

This function is called if the user cancels in-place renaming of this item in column col (e.g. by pressing Esc). It's the "nvm bestie" of rename flows. 😌

See also okRename().


✨ int QListViewItem::childCount () const ✨

Returns how many children this item has. The count only includes the item's immediate children. No grandkids allowed in this number. πŸ‘ΆπŸš«


πŸ”₯ int QListViewItem::compare ( QListViewItem * i, int col, bool ascending ) const [virtual] πŸ”₯

Compares this list view item to i using the column col in ascending order. Returns < 0 if this item is less than i, 0 if they are equal, and > 0 if this item is greater than i.

This function is used for sorting.

The default implementation compares the item keys (key()) using QString::localeAwareCompare(). A reimplementation can use different values and a different comparison function. Here is a reimplementation that uses plain Unicode comparison:

int MyListViewItem::compare( QListViewItem *i, int col,
                             bool ascending ) const
{
    return key( col, ascending ).compare( i->key( col, ascending) );
}

We don't recommend using ascending so your code can safely ignore it.

See also key(), QString::localeAwareCompare(), and QString::compare().


🌈 int QListViewItem::depth () const 🌈

Returns the depth of this item. How deep does the tree go? This tells you. 🌳

Example: dirview/dirview.cpp.


πŸ’… bool QListViewItem::dragEnabled () const πŸ’…

Returns TRUE if this item can be dragged; otherwise returns FALSE.

See also setDragEnabled().


🫢 void QListViewItem::dragEntered () [virtual protected] 🫢

This function is called when a drag enters the item's bounding rectangle.

The default implementation does nothing, subclasses may need to reimplement this function. So if you want drag glow-up, you gotta code it. ✨


πŸ“ void QListViewItem::dragLeft () [virtual protected] πŸ“

This function is called when a drag leaves the item's bounding rectangle.

The default implementation does nothing, subclasses may need to reimplement this function. It's the "ok bye" of drag events. πŸ‘‹


🌟 bool QListViewItem::dropEnabled () const 🌟

Returns TRUE if this item accepts drops; otherwise returns FALSE.

See also setDropEnabled() and acceptDrop().


πŸ’– void QListViewItem::dropped ( QDropEvent * e ) [virtual protected] πŸ’–

This function is called when something was dropped on the item. e contains all the information about the drop.

The default implementation does nothing, subclasses may need to reimplement this function. Drop it like it's hot, but only if you override. πŸ”₯


🧚 void QListViewItem::enforceSortOrder () const [virtual protected] 🧚

Makes sure that this object's children are sorted appropriately.

This only works if every item from the root item down to this item is already sorted. So no skipping steps, bestie. πŸ“

See also sortChildItems().


πŸ‘‘ QListViewItem * QListViewItem::firstChild () const πŸ‘‘

Returns the first (top) child of this item, or 0 if this item has no children.

Note that the children are not guaranteed to be sorted properly. QListView and QListViewItem try to postpone or avoid sorting to the greatest degree possible, in order to keep the user interface snappy. So yeah, it's fast but maybe not perfectly ordered. ⚑

See also nextSibling() and sortChildItems().

Example: checklists/checklists.cpp.


🌸 int QListViewItem::height () const 🌸

Returns the height of this item in pixels. This does not include the height of any children; totalHeight() returns that. So this is just the item's own vertical vibe. πŸ“


πŸ’€ void QListViewItem::insertItem ( QListViewItem * newChild ) [virtual] πŸ’€

Inserts newChild into this list view item's list of children. You should not need to call this function; it is called automatically by the constructor of newChild.

Warning: If you are using Single selection mode, then you should only insert unselected items.

So don't be out here inserting selected items in Single selection mode. That's a no-no. 🚫


✨ void QListViewItem::invalidateHeight () [virtual] ✨

Invalidates the cached total height of this item, including all open children. Basically telling the cache "you're wrong, bestie, recalculate." πŸ’…

See also setHeight(), height(), and totalHeight().


πŸ¦‹ bool QListViewItem::isEnabled () const πŸ¦‹

Returns TRUE if this item is enabled; otherwise returns FALSE.

See also setEnabled().


πŸŽ€ bool QListViewItem::isExpandable () const πŸŽ€

Returns TRUE if this item is expandable even when it has no children; otherwise returns FALSE. So it can look expandable before it actually has kids. Iconic. πŸ‘‘


πŸ’œ bool QListViewItem::isOpen () const πŸ’œ

Returns TRUE if this list view item has children and they are not explicitly hidden; otherwise returns FALSE.

See also setOpen().


πŸ”₯ bool QListViewItem::isSelectable () const πŸ”₯

Returns TRUE if the item is selectable (as it is by default); otherwise returns FALSE.

See also setSelectable().


🌈 bool QListViewItem::isSelected () const 🌈

Returns TRUE if this item is selected; otherwise returns FALSE.

See also setSelected(), QListView::setSelected(), and QListView::selectionChanged().

Example: listviews/listviews.cpp.


🫢 bool QListViewItem::isVisible () const 🫢

Returns TRUE if the item is visible; otherwise returns FALSE.

See also setVisible().


πŸ“ QListViewItem * QListViewItem::itemAbove () πŸ“

Returns a pointer to the item immediately above this item on the screen. This is usually the item's closest older sibling, but it may also be its parent or its next older sibling's youngest child, or something else if anyoftheabove->height() returns 0. Returns 0 if there is no item immediately above this item.

This function assumes that all parents of this item are open (i.e. that this item is visible, or can be made visible by scrolling).

This function might be relatively slow because of the tree traversions needed to find the correct item. So don't call it in a tight loop unless you're ready. 😭

See also itemBelow() and QListView::itemRect().


🌟 QListViewItem * QListViewItem::itemBelow () 🌟

Returns a pointer to the item immediately below this item on the screen. This is usually the item's eldest child, but it may also be its next younger sibling, its parent's next younger sibling, grandparent's, etc., or something else if anyoftheabove->height() returns 0. Returns 0 if there is no item immediately below this item.

This function assumes that all parents of this item are open (i.e. that this item is visible or can be made visible by scrolling).

See also itemAbove() and QListView::itemRect().

Example: dirview/dirview.cpp.


πŸ’– int QListViewItem::itemPos () const πŸ’–

Returns the y coordinate of this item in the list view's coordinate system. This function is normally much slower than QListView::itemAt(), but it works for all items whereas QListView::itemAt() normally only works for items on the screen. So it's the slow-but-reliable bestie. 🐒

See also QListView::itemAt(), QListView::itemRect(), and QListView::itemPos().


🧚 QString QListViewItem::key ( int column, bool ascending ) const [virtual] 🧚

Returns a key that can be used for sorting by column column. The default implementation returns text(). Derived classes may also incorporate the order indicated by ascending into this key, although this is not recommended.

If you want to sort on non-alphabetical data, e.g. dates, numbers, etc., it is more efficient to reimplement compare().

See also compare() and sortChildItems().


πŸ‘‘ QListView * QListViewItem::listView () const πŸ‘‘

Returns a pointer to the list view containing this item.

Note that this function traverses the items to the root to find the listview. This function will return 0 for taken items - see QListViewItem::takeItem().


✨ void QListViewItem::moveItem ( QListViewItem * after ) ✨

Move the item to be after item after, which must be one of the item's siblings. To move an item in the hierarchy, use takeItem() and insertItem().

Note that this function will have no effect if sorting is enabled in the list view. So if sorting is on, this move is not moving. πŸ’€


πŸ’… bool QListViewItem::multiLinesEnabled () const πŸ’…

Returns TRUE if the item can display multiple lines of text in its columns; otherwise returns FALSE.


πŸ¦‹ QListViewItem * QListViewItem::nextSibling () const πŸ¦‹

Returns the sibling item below this item, or 0 if there is no sibling item after this item.

Note that the siblings are not guaranteed to be sorted properly. QListView and QListViewItem try to postpone or avoid sorting to the greatest degree possible, in order to keep the user interface snappy.

See also firstChild() and sortChildItems().

Example: xml/tagreader-with-features/structureparser.cpp.


πŸŽ€ void QListViewItem::okRename ( int col ) [virtual protected] πŸŽ€

This function is called if the user presses Enter during in-place renaming of the item in column col. It's the "yes, commit that" moment. βœ…

See also cancelRename().


πŸ”₯ void QListViewItem::paintBranches ( QPainter * p, const QColorGroup & cg, int w, int y, int h ) [virtual] πŸ”₯

Paints a set of branches from this item to (some of) its children.

Painter p is set up with clipping and translation so that you can only draw in the rectangle that needs redrawing; cg is the color group to use; the update rectangle is at (0, 0) and has size width w by height h. The top of the rectangle you own is at y (which is never greater than 0 but can be outside the window system's allowed coordinate range).

The update rectangle is in an undefined state when this function is called; this function must draw on all of the pixels. So no leaving blank spots, bestie. 🎨

See also paintCell() and QListView::drawContentsOffset().

void QListViewItem::paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ) [virtual]

Okay so this one is the one you override when you want your item to look like ✨yours✨. It paints the contents of one column of an item and aligns it as described by align.

Here's the tea on the painter, bestie, because the rules are strict:

  • p is a QPainter open on the relevant paint device, and p is translated so (0, 0) is the top-left pixel in the cell and width-1, height()-1 is the bottom-right pixel in the cell.
  • The other properties of p (pen, brush, etc) are undefined β€” do not assume anything about them. πŸ™ˆ
  • cg is the color group to use.
  • column is the logical column number within the item that is to be painted; 0 is the column which may contain a tree. 🌳

This function may use QListView::itemMargin() for readability spacing on the left and right sides of data such as text, and should honor isSelected() and QListView::allColumnsShowFocus().

If you reimplement this function, you should also reimplement width(). They're a package deal, no cap. πŸ’…

The rectangle to be painted is in an undefined state when this function is called, so you must draw on all the pixels. No skipping, no leaving crumbs. The painter p has the right font on entry.

See also paintBranches() and QListView::drawContentsOffset().

Example: listviews/listviews.cpp.

Reimplemented in QCheckListItem.


void QListViewItem::paintFocus ( QPainter * p, const QColorGroup & cg, const QRect & r ) [virtual]

Paints a focus indicator on the rectangle r using painter p and colors cg.

p is already clipped, so like… you're fine, don't stress. 🌸

See also paintCell(), paintBranches(), and QListView::allColumnsShowFocus.

Reimplemented in QCheckListItem.


QListViewItem * QListViewItem::parent () const

Returns the parent of this item, or 0 if this item has no parent. So if it returns 0… you're the root, main character energy, nobody above you. πŸ‘‘

See also firstChild() and nextSibling().

Examples:


const QPixmap * QListViewItem::pixmap ( int column ) const [virtual]

Returns the pixmap for column, or 0 if there is no pixmap for column. Empty-handed vibes, it happens. 🫢

See also setText() and setPixmap().

Example: dirview/dirview.cpp.


void QListViewItem::removeItem ( QListViewItem * item ) [virtual]

⚠️ This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

This function has been renamed takeItem(). That's it, that's the whole thing β€” it's giving "we changed the name and kept the old one around for the elders." πŸ’€


bool QListViewItem::renameEnabled ( int col ) const

Returns TRUE if this item can be in-place renamed in column col; otherwise returns FALSE.


void QListViewItem::repaint () const

Repaints this item on the screen if it is currently visible. If it's hidden, this is just a vibe check that fails, bestie. 🌈

Example: addressbook/centralwidget.cpp.


int QListViewItem::rtti () const [virtual]

Returns 0.

Make your derived classes return their own values for rtti(), so that you can distinguish between different kinds of list view items. You should use values greater than 1000 to allow for extensions to this class. Like, stay in your lane number-wise, the low numbers are taken. 🚧

Reimplemented in QCheckListItem.


void QListViewItem::setDragEnabled ( bool allow ) [virtual]

If allow is TRUE, the list view starts a drag (see QListView::dragObject()) when the user presses and moves the mouse on this item. Grabby hands mode: activated. βœ‹


void QListViewItem::setDropEnabled ( bool allow ) [virtual]

If allow is TRUE, the list view accepts drops onto the item; otherwise drops are not allowed. 🚫


void QListViewItem::setEnabled ( bool b ) [virtual]

If b is TRUE the item is enabled; otherwise it is disabled. Disabled items are drawn differently (e.g. grayed-out) and are not accessible by the user. It's literally there but also not there. πŸ™ˆ


void QListViewItem::setExpandable ( bool enable ) [virtual]

Sets this item to be expandable even if it has no children if enable is TRUE, and to be expandable only if it has children if enable is FALSE (the default).

The dirview example uses this in the canonical fashion. It checks whether the directory is empty in setup() and calls setExpandable(TRUE) if not; in setOpen() it reads the contents of the directory and inserts items accordingly. This strategy means that dirview can display the entire file system without reading very much at startup. Lazy loading, but make it iconic. πŸ’…

Note that root items are not expandable by the user unless QListView::setRootIsDecorated() is set to TRUE.

See also setSelectable().


void QListViewItem::setHeight ( int height ) [virtual protected]

Sets this item's height to height pixels. This implicitly changes totalHeight(), too.

Note that a font change causes this height to be overwritten unless you reimplement setup(). 😭

For best results in Windows style we suggest using an even number of pixels. Odd numbers, we don't know her. ✨

See also height(), totalHeight(), and isOpen().


void QListViewItem::setMultiLinesEnabled ( bool b ) [virtual]

If b is TRUE each of the item's columns may contain multiple lines of text; otherwise each of them may only contain a single line. Pick your fighter. 🌸


void QListViewItem::setOpen ( bool o ) [virtual]

Opens or closes an item, i.e. shows or hides an item's children.

If o is TRUE all child items are shown initially. The user can hide them by clicking the - icon to the left of the item. If o is FALSE, the children of this item are initially hidden. The user can show them by clicking the + icon to the left of the item. Expand and collapse, the eternal cycle. πŸ¦‹

See also height(), totalHeight(), and isOpen().

Examples:


void QListViewItem::setPixmap ( int column, const QPixmap & pm ) [virtual]

Sets the pixmap in column column to pm, if pm is non-null and different from the current pixmap, and if column is non-negative. Three conditions, all gotta pass, no shortcuts bestie. βœ…

See also pixmap() and setText().

Example: dirview/dirview.cpp.


void QListViewItem::setRenameEnabled ( int col, bool b ) [virtual]

If b is TRUE, this item can be in-place renamed in the column col by the user; otherwise it cannot be renamed in-place. πŸ”’


void QListViewItem::setSelectable ( bool enable ) [virtual]

Sets this item to be selectable if enable is TRUE (the default) or not to be selectable if enable is FALSE.

The user is not able to select a non-selectable item using either the keyboard or the mouse. This also applies for the application programmer (e.g. setSelected() respects this value). So nobody sneaks in the back door, not even you. πŸšͺ

See also isSelectable().


void QListViewItem::setSelected ( bool s ) [virtual]

If s is TRUE this item is selected; otherwise it is deselected.

This function does not maintain any invariants or repaint anything β€” QListView::setSelected() does that. Don't come crying to this function when nothing shows up on screen, it did its one job. πŸ’€

See also height() and totalHeight().

Example: addressbook/centralwidget.cpp.


void QListViewItem::setText ( int column, const QString & text ) [virtual]

Sets the text in column column to text, if column is a valid column number and text is different from the existing text. It's giving "only if you actually changed something." ✨

If text() has been reimplemented, this function may be a no-op. Yeah. Nothing happens. That's allowed.

See also text() and key().

Examples:


void QListViewItem::setVisible ( bool b )

If b is TRUE, the item is made visible; otherwise it is hidden.

If the item is not visible, itemAbove() and itemBelow() will never return this item, although you still can reach it by using e.g. QListViewItemIterator. So like, you're not gone gone, you're just off the grid. πŸ«₯


void QListViewItem::setup () [virtual]

This virtual function is called before the first time QListView needs to know the height or any other graphical attribute of this object, and whenever the font, GUI style, or colors of the list view change. So it gets summoned a lot. πŸ“£

The default calls widthChanged() and sets the item's height to the height of a single line of text in the list view's font. (If you use icons, multi-line text, etc., you will probably need to call setHeight() yourself or reimplement it.)

Example: dirview/dirview.cpp.


void QListViewItem::sort () [virtual]

Sorts all this item's child items using the current sorting configuration (sort column and direction). Put the kids in order. πŸŽ€

See also enforceSortOrder().


void QListViewItem::sortChildItems ( int column, bool ascending ) [virtual]

Sorts this item's children using column column. This is done in ascending order if ascending is TRUE and in descending order if ascending is FALSE.

Asks some of the children to sort their children. (QListView and QListViewItem ensure that all on-screen objects are properly sorted but may avoid or defer sorting other objects in order to be more responsive.) Prioritizing what's visible? That's just good time management fr fr. ⭐

See also key() and compare().


void QListViewItem::startRename ( int col ) [virtual]

If in-place renaming of this item is enabled (see renameEnabled()), this function starts renaming the item in column col, by creating and initializing an edit box. Go on, type, it's your moment. ✍️


void QListViewItem::takeItem ( QListViewItem * item ) [virtual]

Removes item from this object's list of children and causes an update of the screen display. The item is not deleted. You should not normally need to call this function because QListViewItem::~QListViewItem() calls it.

The normal way to delete an item is to use delete.

If you need to move an item from one place in the hierarchy to another you can use takeItem() to remove the item from the list view and then insertItem() to put the item back in its new position. Detach, relocate, reattach. 🚚

If a taken item is part of a selection in Single selection mode, it is unselected and selectionChanged() is emitted. If a taken item is part of a selection in Multi or Extended selection mode, it remains selected. Different rules for different modes, iykyk.

⚠️ Warning: This function leaves item and its children in a state where most member functions are unsafe. Only a few functions work correctly on an item in this state, most notably insertItem(). The functions that work on taken items are explicitly documented as such. Handle with care, bestie, that item is in the ✨liminal space✨.

See also QListViewItem::insertItem().


QString QListViewItem::text ( int column ) const [virtual]

Returns the text in column column, or QString::null if there is no text in that column. Empty column, empty string, empty vibes. πŸ“

See also key() and paintCell().

Examples:


int QListViewItem::totalHeight () const

Returns the total height of this object, including any visible children. This height is recomputed lazily and cached for as long as possible. Lazy but efficient, honestly same. 😴

Functions which can affect the total height are, setHeight() which is used to set an item's height, setOpen() to show or hide an item's children, and invalidateHeight() to invalidate the cached height.

See also height().


int QListViewItem::width ( const QFontMetrics & fm, const QListView * lv, int c ) const [virtual]

Returns the number of pixels of width required to draw column c of list view lv, using the metrics fm without cropping. The list view containing this item may use this information depending on the QListView::WidthMode settings for the column.

The default implementation returns the width of the bounding rectangle of the text of column c.

See also listView(), widthChanged(), QListView::setColumnWidthMode(), and QListView::itemMargin.


void QListViewItem::widthChanged ( int c = -1 ) const

Call this function when the value of width() may have changed for column c. Normally, you should call this if text(c) changes. Passing -1 for c indicates that all columns may have changed. It is more efficient to pass -1 if two or more columns have changed than to call widthChanged() separately for each one. One call, all the columns, that's the move. πŸ’…

See also width().


✨ SEE ALSO ✨

Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. Bestie, the full legal tea is in the license file that ships with the distribution β€” go read it there for the complete license statement, okay? It's giving "the receipts are in the folder." πŸŽ€


✍️ AUTHOR ✍️

Generated automatically from the source code. No human sat there writing this by hand at 3am β€” the machine did it. Robotic queen behavior, honestly. πŸ€–πŸ’…


πŸ› BUGS πŸ›

Okay so if you find a bug in Qt, pls report it exactly the way they describe over at http://doc.trolltech.com/bughowto.html. Good bug reports help them help you β€” it's a whole mutual-aid situation and they mean it. Thank you!! 🫢

The definitive Qt documentation is the HTML one, fr fr. It lives at $QTDIR/doc/html and you can read it with Qt Assistant or literally just any web browser. This man page? It's a convenience for the girlies who prefer man pages, but ngl β€” this format is not officially supported by Trolltech. Not official, just thoughtful. πŸ™ˆ

And if you spot errors in this manual page specifically, send them to qt-bugs@trolltech.com. Please include the name of the manual page (qlistviewitem.3qt) and the Qt version (3.3.8) β€” otherwise they're out here playing detective and nobody has time for that. πŸ”πŸ’€

Lowkey important: without those two deets (page name + version) your report is just a vibe with no context. Include them. Periodt. πŸ‘‘

Trolltech AS Β· 2 February 2007 Β· QListViewItem(3qt)

And that's the whole page, bestie β€” every last copyright line, author credit, bug-reporting ritual, and that lil footer stamp from Trolltech AS dated 2 February 2007, closing out QListViewItem(3qt). You read all four parts, which is honestly main character energy. Go build something iconic with it. πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from