QListBox(3qt)

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

QListBox πŸ’–

okay bestie, welcome to the QListBox(3qt) page β€” yes, that's the manual name, we're doing this properly. This is the Qt widget that's basically a list of selectable, read-only items. Think: a scrollable pile of things you can pick from, but you can't type into them. Iconic. Let's get into it. πŸŽ€


NAME πŸ’…

QListBox β€” a list of selectable, read-only items. That's it, that's the whole vibe. πŸ¦‹


SYNOPSIS ✨

First things first, you gotta pull in the header:

#include <qlistbox.h

wait no β€” bestie, exact characters, it's:

#include <qlistbox.h>

okay periodt. Also, lowkey important: this class inherits QScrollView. Keep that in your notes. πŸ“

Public Members 🫢

Here's the whole roster of public members, every single one, no skips:

  • QListBox ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
  • ~QListBox ()
  • uint count () const
  • void insertStringList ( const QStringList & list, int index = -1 )
  • void insertStrList ( const QStrList * list, int index = -1 )
  • void insertStrList ( const QStrList & list, int index = -1 )
  • void insertStrList ( const char ** strings, int numStrings = -1, int index = -1 )
  • void insertItem ( const QListBoxItem * lbi, int index = -1 )
  • void insertItem ( const QListBoxItem * lbi, const QListBoxItem * after )
  • void insertItem ( const QString & text, int index = -1 )
  • void insertItem ( const QPixmap & pixmap, int index = -1 )
  • void insertItem ( const QPixmap & pixmap, const QString & text, int index = -1 )
  • void removeItem ( int index )
  • QString text ( int index ) const
  • const QPixmap * pixmap ( int index ) const
  • void changeItem ( const QListBoxItem * lbi, int index )
  • void changeItem ( const QString & text, int index )
  • void changeItem ( const QPixmap & pixmap, int index )
  • void changeItem ( const QPixmap & pixmap, const QString & text, int index )
  • void takeItem ( const QListBoxItem * item )
  • int numItemsVisible () const
  • int currentItem () const
  • QString currentText () const
  • virtual void setCurrentItem ( int index )
  • virtual void setCurrentItem ( QListBoxItem * i )
  • void centerCurrentItem () (obsolete)
  • int topItem () const
  • virtual void setTopItem ( int index )
  • virtual void setBottomItem ( int index )
  • long maxItemWidth () const
  • enum SelectionMode { Single, Multi, Extended, NoSelection }
  • virtual void setSelectionMode ( SelectionMode )
  • SelectionMode selectionMode () const
  • void setMultiSelection ( bool multi ) (obsolete)
  • bool isMultiSelection () const (obsolete)
  • virtual void setSelected ( QListBoxItem * item, bool select )
  • void setSelected ( int index, bool select )
  • bool isSelected ( int i ) const
  • bool isSelected ( const QListBoxItem * i ) const
  • QListBoxItem * selectedItem () const
  • QListBoxItem * item ( int index ) const
  • int index ( const QListBoxItem * lbi ) const
  • QListBoxItem * findItem ( const QString & text, ComparisonFlags compare = BeginsWith ) const
  • void triggerUpdate ( bool doLayout )
  • bool itemVisible ( int index )
  • bool itemVisible ( const QListBoxItem * item )
  • enum LayoutMode { FixedNumber, FitToWidth, FitToHeight = FitToWidth, Variable }
  • virtual void setColumnMode ( LayoutMode )
  • virtual void setColumnMode ( int )
  • virtual void setRowMode ( LayoutMode )
  • virtual void setRowMode ( int )
  • LayoutMode columnMode () const
  • LayoutMode rowMode () const
  • int numColumns () const
  • int numRows () const
  • bool variableWidth () const
  • virtual void setVariableWidth ( bool )
  • bool variableHeight () const
  • virtual void setVariableHeight ( bool )
  • bool autoScrollBar () const (obsolete)
  • void setAutoScrollBar ( bool enable ) (obsolete)
  • bool scrollBar () const (obsolete)
  • void setScrollBar ( bool enable ) (obsolete)
  • bool autoBottomScrollBar () const (obsolete)
  • void setAutoBottomScrollBar ( bool enable ) (obsolete)
  • bool bottomScrollBar () const (obsolete)
  • void setBottomScrollBar ( bool enable ) (obsolete)
  • int inSort ( const QListBoxItem * lbi ) (obsolete)
  • int inSort ( const QString & text ) (obsolete)
  • int cellHeight ( int i ) const (obsolete)
  • int cellHeight () const (obsolete)
  • int cellWidth () const (obsolete)
  • int numCols () const (obsolete)
  • int itemHeight ( int index = 0 ) const
  • QListBoxItem * itemAt ( const QPoint & p ) const
  • QRect itemRect ( QListBoxItem * item ) const
  • QListBoxItem * firstItem () const
  • void sort ( bool ascending = TRUE )
ngl bestie, see all those (obsolete) tags? Those ones are old. Still in the docs, still listed, but they're the "this is giving legacy" crowd. Don't build your whole personality around them. 😭

Public Slots πŸ”₯

These are the slots you can wire up, all of them:

  • void clear ()
  • virtual void ensureCurrentVisible ()
  • virtual void clearSelection ()
  • virtual void selectAll ( bool select )
  • virtual void invertSelection ()

Signals ⭐

The signals this widget sends out into the world. Every single one, bestie:

  • void highlighted ( int index )
  • void selected ( int index )
  • void highlighted ( const QString & )
  • void selected ( const QString & )
  • void highlighted ( QListBoxItem * )
  • void selected ( QListBoxItem * )
  • void selectionChanged ()
  • void selectionChanged ( QListBoxItem * item )
  • void currentChanged ( QListBoxItem * item )
  • void clicked ( QListBoxItem * item )
  • void clicked ( QListBoxItem * item, const QPoint & pnt )
  • void pressed ( QListBoxItem * item )
  • void pressed ( QListBoxItem * item, const QPoint & pnt )
  • void doubleClicked ( QListBoxItem * item )
  • void returnPressed ( QListBoxItem * )
  • void rightButtonClicked ( QListBoxItem *, const QPoint & )
  • void rightButtonPressed ( QListBoxItem *, const QPoint & )
  • void mouseButtonPressed ( int button, QListBoxItem * item, const QPoint & pos )
  • void mouseButtonClicked ( int button, QListBoxItem * item, const QPoint & pos )
  • void contextMenuRequested ( QListBoxItem * item, const QPoint & pos )
  • void onItem ( QListBoxItem * i )
  • void onViewport ()

Properties 🌸

the vibe check on the properties β€” each one with its lil description:

  • LayoutMode columnMode β€” the column layout mode for this list box
  • uint count β€” the number of items in the list box (read only)
  • int currentItem β€” the current highlighted item
  • QString currentText β€” the text of the current item (read only)
  • bool multiSelection β€” whether or not the list box is in Multi selection mode (obsolete)
  • int numColumns β€” the number of columns in the list box (read only)
  • int numItemsVisible β€” the number of visible items (read only)
  • int numRows β€” the number of rows in the list box (read only)
  • LayoutMode rowMode β€” the row layout mode for this list box
  • SelectionMode selectionMode β€” the selection mode of the list box
  • int topItem β€” the index of an item at the top of the screen
  • bool variableHeight β€” whether this list box has variable-height rows
  • bool variableWidth β€” whether this list box has variable-width columns

Protected Members πŸ™ˆ

the protected zone, for when you're subclassing and feeling main character:

  • void updateItem ( int index )
  • void updateItem ( QListBoxItem * i )
  • int totalWidth () const (obsolete)
  • int totalHeight () const (obsolete)
  • virtual void paintCell ( QPainter * p, int row, int col )
  • void toggleCurrentItem ()
  • bool isRubberSelecting () const
  • void doLayout () const
  • bool itemYPos ( int index, int * yPos ) const (obsolete)
  • int findItem ( int yPos ) const (obsolete)

that's the whole synopsis bestie, and there's so much more coming β€” this page is long and we are not done. 🧚

✨ DESCRIPTION ✨

okay so bestie, the QListBox widget gives you a list of selectable, read-only items. that's the whole vibe πŸ’…

it's typically a single-column list where either nothing is selected or exactly one thing is selected, but ngl you can absolutely use it in a bunch of other ways too. she's flexible like that πŸ¦‹

QListBox will add scroll bars as necessary, but like... she is NOT built for giant lists, ok? if you want more than a few thousand items, it's probably better to use a different widget β€” mainly because the scroll bars won't give you very good navigation, but also because QListBox may become slow with huge lists. (peep QListView and QTable for possible alternatives πŸ‘€)

there are a variety of selection modes described in the QListBox::SelectionMode documentation. the default is Single selection mode, but you can change it using setSelectionMode(). (setMultiSelection() is still provided for compatibility with Qt 1.x β€” we recommend using setSelectionMode() in all code, fr fr, no cap 🫢)

because QListBox offers multiple selection it must display keyboard focus and selection state separately. so there are functions both to set the selection state of an item, i.e. setSelected(), and to set which item displays keyboard focus, i.e. setCurrentItem(). two different things bestie, don't mix them up πŸ’–

the list box normally arranges its items in a single column and adds a vertical scroll bar if required. it is possible to have:

  • a different fixed number of columns (setColumnMode())
  • as many columns as will fit in the list box's assigned screen space (setColumnMode(FitToWidth))
  • a fixed number of rows (setRowMode())
  • as many rows as will fit in the list box's assigned screen space (setRowMode(FitToHeight))

in ALL these cases QListBox will add scroll bars, as appropriate, in at least one direction. iconic behavior honestly πŸ‘‘

if multiple rows are used, each row can be as high as necessary (the normal setting), or you can request that all items will have the same height by calling setVariableHeight(FALSE). same deal for a column's width, see setVariableWidth(). ✨

the QListBox's items are QListBoxItem objects. QListBox provides methods to insert new items as strings, as pixmaps, and as QListBoxItem * (insertItem() with various arguments), and to replace an existing item with a new string, pixmap or QListBoxItem (changeItem() with various arguments). you can also remove items singly with removeItem() or clear() the entire list box. note that if you create a QListBoxItem yourself and insert it, QListBox takes ownership of the item. πŸ‘ˆ remember this one

you can also create a QListBoxItem, such as QListBoxText or QListBoxPixmap, with the list box as first parameter. the item will then append itself. and when you delete an item it is automatically removed from the list box. self-cleaning queen 🧚

the list of items can be arbitrarily large; QListBox will add scroll bars if necessary. QListBox can display a single-column (the common case) or multiple-columns, and offers both single and multiple selection. QListBox does not support multiple-column items (but QListView and QTable do), or tree hierarchies (but QListView does). know her limits bestie 😭

the list box items can be accessed both as QListBoxItem objects (recommended πŸ’–) and using integer indexes (the original QListBox implementation used an array of strings internally, and the API still supports this mode of operation). everything can be done using the new objects, and most things can be done using indexes.

each item in a QListBox contains a QListBoxItem. one of the items can be the current item. the currentChanged() signal and the highlighted() signal are emitted when a new item becomes current, e.g. because the user clicks on it or QListBox::setCurrentItem() is called. the selected() signal is emitted when the user double-clicks on an item or presses Enter on the current item. πŸ“£

if the user does not select anything, no signals are emitted and currentItem() returns -1.

a list box has WheelFocus as a default focusPolicy(), i.e. it can get keyboard focus by tabbing, clicking and through the use of the mouse wheel. ✨

new items can be inserted using insertItem(), insertStrList() or insertStringList(). inSort() is obsolete because this method is quite inefficient. it's preferable to insert the items normally and call sort() afterwards, or to insert a sorted QStringList(). do it the good way bestie πŸ’…

by default, vertical and horizontal scroll bars are added and removed as necessary. setHScrollBarMode() and setVScrollBarMode() can be used to change this policy.

if you need to insert types other than strings and pixmaps, you must define new classes which inherit QListBoxItem. get creative πŸŽ€

Warning: the list box assumes ownership of all list box items and will delete them when it does not need them any more. she takes what's hers, periodt πŸ’€
[Image Omitted]

[Image Omitted]

see also QListView, QComboBox, QButtonGroup, GUI Design Handbook: List Box (two sections), and Advanced Widgets. πŸ¦‹


Member Type Documentation

QListBox::LayoutMode

this enum type is used to specify how QListBox lays out its rows and columns.

  • QListBox::FixedNumber β€” there is a fixed number of rows (or columns).
  • QListBox::FitToWidth β€” there are as many columns as will fit on-screen.
  • QListBox::FitToHeight β€” there are as many rows as will fit on-screen.
  • QListBox::Variable β€” there are as many rows as are required by the column mode. (or as many columns as required by the row mode.)

example: when you call setRowMode( FitToHeight ), columnMode() automatically becomes Variable to accommodate the row mode you've set. she adapts, she slays πŸ’…

QListBox::SelectionMode

this enumerated type is used by QListBox to indicate how it reacts to selection by the user.

  • QListBox::Single β€” when the user selects an item, any already-selected item becomes unselected and the user cannot unselect the selected item. this means that the user can never clear the selection, even though the selection may be cleared by the application programmer using QListBox::clearSelection().
  • QListBox::Multi β€” when the user selects an item the selection status of that item is toggled and the other items are left alone. also, multiple items can be selected by dragging the mouse while the left mouse button is kept pressed.
  • QListBox::Extended β€” when the user selects an item the selection is cleared and the new item selected. however, if the user presses the Ctrl key when clicking on an item, the clicked item gets toggled and all other items are left untouched. and if the user presses the Shift key while clicking on an item, all items between the current item and the clicked item get selected or unselected, depending on the state of the clicked item. also, multiple items can be selected by dragging the mouse while the left mouse button is kept pressed.
  • QListBox::NoSelection β€” items cannot be selected.

in other words, Single is a real single-selection list box, Multi is a real multi-selection list box, Extended is a list box in which users can select multiple items but usually want to select either just one or a range of contiguous items, and NoSelection is for a list box where the user can look but not touch. πŸ‘€βœ¨


🌸 MEMBER FUNCTION DOCUMENTATION 🌸

QListBox::QListBox ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )

constructs a new empty list box called name and with parent parent. brand new, fresh out the box πŸŽ€

performance is boosted by modifying the widget flags f so that only part of the QListBoxItem children is redrawn. this may be unsuitable for custom QListBoxItem classes, in which case WStaticContents and WNoAutoErase should be cleared immediately after construction. πŸ‘ˆ custom class girlies pay attention

see also QWidget::clearWFlags() and Qt::WidgetFlags.

QListBox::~QListBox ()

destroys the list box. deletes all list box items. bye bestie πŸ’€πŸ‘‹

bool QListBox::autoBottomScrollBar () const

this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.

returns TRUE if hScrollBarMode() is Auto; otherwise returns FALSE.

bool QListBox::autoScrollBar () const

this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.

returns TRUE if vScrollBarMode() is Auto; otherwise returns FALSE.

bool QListBox::bottomScrollBar () const

this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.

returns FALSE if vScrollBarMode() is AlwaysOff; otherwise returns TRUE.

int QListBox::cellHeight ( int i ) const

this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.

returns the item height of item i.

see also itemHeight().

int QListBox::cellHeight () const

this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.

this is an overloaded member function, provided for convenience. it behaves essentially like the above function.

returns the item height of the first item, item 0.

see also itemHeight().

int QListBox::cellWidth () const

this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.

returns the maximum item width.

see also maxItemWidth().

void QListBox::centerCurrentItem ()

this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code.

this function does exactly the same as ensureCurrentVisible().

see also QListBox::ensureCurrentVisible().

void QListBox::changeItem ( const QListBoxItem * lbi, int index )

replaces the item at position index with lbi. if index is negative or too large, changeItem() does nothing. (no drama, she just ignores you πŸ™ˆ)

the item that has been changed will become selected. πŸ’–

see also insertItem() and removeItem().

void QListBox::changeItem ( const QString & text, int index )

this is an overloaded member function, provided for convenience. it behaves essentially like the above function.

replaces the item at position index with a new list box text item with text text.

the operation is ignored if index is out of range.

see also insertItem() and removeItem().

void QListBox::changeItem ( const QPixmap & pixmap, int index )

this is an overloaded member function, provided for convenience. it behaves essentially like the above function.

replaces the item at position index with a new list box pixmap item with pixmap pixmap.

the operation is ignored if index is out of range.

see also insertItem() and removeItem().

void QListBox::changeItem ( const QPixmap & pixmap, const QString & text, int index )

this is an overloaded member function, provided for convenience. it behaves essentially like the above function.

replaces the item at position index with a new list box pixmap item with pixmap pixmap and text text. ✨

the operation is ignored if index is out of range.

see also insertItem() and removeItem().

void QListBox::clear () [slot]

deletes all the items in the list. wipeout, clean slate, fresh start 🧹✨

see also removeItem().

void QListBox::clearSelection () [virtual slot]

Un-selects every single item, if that's even possible for the list box in question. ✨

Heads up bestie: a Single selection list box is gonna auto-select an item anyway if it has keyboard focus. It just does that. No, you can't stop it. πŸ’…

Example: listbox/listbox.cpp.


void QListBox::clicked ( QListBoxItem * item ) [signal]

Fires the moment the user clicks <em>any</em> mouse button β€” left, right, middle, all of them, we don't discriminate. πŸ–±οΈ If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item at all.

⚠️ Do NOT delete any QListBoxItem objects in slots connected to this signal. Fr fr. Just don't. It will not go well. πŸ’€

void QListBox::clicked ( QListBoxItem * item, const QPoint & pnt ) [signal]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Same energy: emitted when the user clicks any mouse button. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item. 🌸

pnt is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()). (And if the click's press and release differ by a pixel or two, pnt is the position at release time. 🫢)

⚠️ Again, bestie, you must not delete any QListBoxItem objects in slots connected to this signal. Consider this your official warning. 😭

LayoutMode QListBox::columnMode () const

Returns the column layout mode for this list box. See the "columnMode" property for the deets. πŸ‘‘


void QListBox::contextMenuRequested ( QListBoxItem * item, const QPoint & pos ) [signal]

Context menu time!! Emitted when the user invokes a context menu β€” either by right-clicking with the mouse, or by using the special system keys (iykyk, the menu key girlies). πŸŽ€

item is the item under the mouse cursor, or the current item, respectively. pos is the position for the context menu in the global coordinate system.


uint QListBox::count () const

Returns the number of items in the list box. That's it, that's the whole vibe. See the "count" property for details. πŸ”’


void QListBox::currentChanged ( QListBoxItem * item ) [signal]

Emitted when the user makes a new item the current item. item is the new current list box item, main character of the moment. ⭐

See also currentItem and currentItem.


int QListBox::currentItem () const

Returns the current highlighted item. See the "currentItem" property for details. πŸ’–


QString QListBox::currentText () const

Returns the text of the current item. See the "currentText" property for details. ✨


void QListBox::doLayout () const [protected]

This function does the hard layout work. It's the behind-the-scenes queen doing all the heavy lifting. πŸ’… You should never need to call it. Like, genuinely never. Leave her alone, she's busy.


void QListBox::doubleClicked ( QListBoxItem * item ) [signal]

Emitted whenever an item is double-clicked. πŸ‘†πŸ‘† And ngl, the timing is specific: it's emitted on the second button press, not the second button release. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.


void QListBox::ensureCurrentVisible () [virtual slot]

Makes sure the current item is visible. Scrolling into frame like the icon it is. πŸ”₯


QListBoxItem * QListBox::findItem ( const QString & text, ComparisonFlags compare = BeginsWith ) const

Finds the first list box item that has the text text and returns it β€” or returns 0 if no such item could be found. πŸ™ˆ

The search starts from the current item if the current item exists; otherwise it starts from the first list box item. And if ComparisonFlags are specified in compare, those flags get used. Otherwise the default is a case-insensitive, "begins with" search. 🌸

See also Qt::StringComparisonMode.


int QListBox::findItem ( int yPos ) const [protected]

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

Returns the index of the item at point (0, yPos).

See also index() and itemAt().


QListBoxItem * QListBox::firstItem () const

Returns the first item in this list box. And if the list box is empty? Returns 0. Nothing there, bestie. πŸ«₯


void QListBox::highlighted ( int index ) [signal]

Emitted when the user makes a new item the current item. index is the index of the new current item. πŸ‘‘

See also currentChanged(), selected(), currentItem, and selectionChanged().


void QListBox::highlighted ( const QString & ) [signal]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Emitted when the user makes a new item the current item and the item is (or has) a string. The argument is the text of the new current item. πŸ’¬

See also currentChanged(), selected(), currentItem, and selectionChanged().


void QListBox::highlighted ( QListBoxItem * ) [signal]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Emitted when the user makes a new item the current item. The argument is a pointer to the new current item. 🎯

See also currentChanged(), selected(), currentItem, and selectionChanged().


int QListBox::inSort ( const QListBoxItem * lbi )

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

Also, using this method is quite inefficient. We suggest to use insertItem() for inserting and sort() afterwards. πŸ’€

Inserts lbi at its sorted position in the list box and returns the position.

⚠️ All items must be inserted with inSort() to maintain the sorting order. And inSort() treats any pixmap (or user-defined type) as lexicographically less than any string. Yes, that's a real rule, no I don't make them.

See also insertItem() and sort().


int QListBox::inSort ( const QString & text )

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Using this method is quite inefficient. We suggest to use insertItem() for inserting and sort() afterwards.

Inserts a new item of text at its sorted position in the list box and returns the position. πŸ“₯

⚠️ All items must be inserted with inSort() to maintain the sorting order. inSort() treats any pixmap (or user-defined type) as lexicographically less than any string.

See also insertItem() and sort().


int QListBox::index ( const QListBoxItem * lbi ) const

Returns the index of lbi β€” or -1 if the item is not in this list box, or if lbi is 0. Not found? -1. Simple as. πŸ™ƒ

See also item().


void QListBox::insertItem ( const QListBoxItem * lbi, int index = -1 )

Inserts the item lbi into the list at position index. πŸŽ€

If index is negative or larger than the number of items in the list box, lbi is inserted at the end of the list.

See also insertStrList().

Examples:


void QListBox::insertItem ( const QListBoxItem * lbi, const QListBoxItem * after )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts the item lbi into the list after the item after β€” or at the beginning if after is 0. 🫢

See also insertStrList().


void QListBox::insertItem ( const QString & text, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a new list box text item with the text text into the list at position index. πŸ’¬

If index is negative, text is inserted at the end of the list.

See also insertStrList().


void QListBox::insertItem ( const QPixmap & pixmap, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a new list box pixmap item with the pixmap pixmap into the list at position index. πŸ–ΌοΈ

If index is negative, pixmap is inserted at the end of the list.

See also insertStrList().


void QListBox::insertItem ( const QPixmap & pixmap, const QString & text, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a new list box pixmap item with the pixmap pixmap and the text text into the list at position index. The whole package. ✨

If index is negative, pixmap is inserted at the end of the list.

See also insertStrList().


void QListBox::insertStrList ( const QStrList * list, int index = -1 )

Inserts the string list list into the list at position index. πŸ“‹

If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.

⚠️ Warning: This function uses const char * rather than QString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real QStrings.
⚠️ Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStringList().


void QListBox::insertStrList ( const QStrList & list, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts the string list list into the list at position index.

If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.

⚠️ Warning: This function uses const char * rather than QString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real QStrings.
⚠️ Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStringList().


void QListBox::insertStrList ( const char ** strings, int numStrings = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts the numStrings strings of the array strings into the list at position index.

If index is negative, insertStrList() inserts strings at the end of the list. If index is too large, the operation is ignored.

⚠️ Warning: This function uses const char * rather than QString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real QStrings.
⚠️ Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStringList().


void QListBox::insertStringList ( const QStringList & list, int index = -1 )

Inserts the string list list into the list at position index. The good version, using actual QStrings. πŸ’–

If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.

⚠️ Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStrList().


void QListBox::invertSelection () [virtual slot]

Inverts the selection. πŸ”„ Only works in Multi and Extended selection mode β€” in the other modes it's just not the moment, bestie. πŸ’…

bool QListBox::isMultiSelection () const

Returns TRUE if the list box is in Multi selection mode, and FALSE if it's not πŸ’…. Wanna know more? Go read the "multiSelection" property, bestie.


bool QListBox::isRubberSelecting () const [protected]

Returns TRUE if the user is out here selecting items with a rubber band rectangle πŸŽ€, otherwise FALSE. Protected, so it's giving inner-circle only, iykyk.


bool QListBox::isSelected ( int i ) const

Returns TRUE if item i is selected, otherwise FALSE. Simple as that, no cap ✨.


bool QListBox::isSelected ( const QListBoxItem * i ) const

This is an overloaded member function, provided for convenience πŸ’–. It behaves essentially like the above function.

Returns TRUE if item i is selected, otherwise FALSE.


QListBoxItem * QListBox::item ( int index ) const

Hands you a pointer to the item sitting at position index, or 0 if that index is out of bounds πŸ™ˆ.

See also index().

Example: listboxcombo/listboxcombo.cpp.


QListBoxItem * QListBox::itemAt ( const QPoint & p ) const

Returns the item at point p β€” and p is in viewport coordinates, bestie, don't forget πŸ¦‹ β€” or a 0 if there's literally no item at p.

Use contentsToViewport() to convert between widget coordinates and viewport coordinates πŸ”₯.


int QListBox::itemHeight ( int index = 0 ) const

Returns the height in pixels of the item with index index. And index defaults to 0 ✨.

If index is too large, this function returns 0. Not a crash, just a lil 0 πŸ’€.


QRect QListBox::itemRect ( QListBoxItem * item ) const

Returns the rectangle on the screen that item occupies, in viewport()'s coordinates 🌸. Or an invalid rectangle if item is 0 or isn't currently visible. So like, if you can't see it, you can't measure it, periodt.


bool QListBox::itemVisible ( int index )

Returns TRUE if the item at position index is at least partly visible, otherwise FALSE πŸ‘‘.


bool QListBox::itemVisible ( const QListBoxItem * item )

This is an overloaded member function, provided for convenience 🫢. It behaves essentially like the above function.

Returns TRUE if item is at least partly visible, otherwise FALSE.


bool QListBox::itemYPos ( int index, int * yPos ) const [protected]

⚠️ This function is obsolete. It's only still here to keep old source working, and we strongly advise against using it in new code. Like, please don't, bestie 😭.

Returns the vertical pixel-coordinate in *yPos, of the list box item at position index in the list πŸ“. Returns FALSE if the item is outside the visible area.


long QListBox::maxItemWidth () const

Returns the width of the widest item in the list box πŸ’…. The main character item, basically.


void QListBox::mouseButtonClicked ( int button, QListBoxItem * item, const QPoint & pos ) [signal]

This signal fires when the user clicks mouse button button πŸ–±οΈ. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item at all.

pos is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()). And here's a lil nuance: if the click's press and release differ by a pixel or two, pos is the position at release time πŸŽ€.

⚠️ Heads up: you must not delete any QListBoxItem objects in slots connected to this signal. Just don't do it πŸ’€.

void QListBox::mouseButtonPressed ( int button, QListBoxItem * item, const QPoint & pos ) [signal]

This signal fires when the user presses mouse button button πŸ”₯. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

pos is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()) ✨.

⚠️ Again for the people in the back: you must not delete any QListBoxItem objects in slots connected to this signal πŸ™ˆ.

int QListBox::numCols () const

⚠️ This function is obsolete. It's provided to keep old source working, and we strongly advise against using it in new code 😭.

Returns the number of columns.

See also numColumns.


int QListBox::numColumns () const

Returns the number of columns in the list box πŸ“Š. See the "numColumns" property for details.


int QListBox::numItemsVisible () const

Returns the number of visible items πŸ‘€. See the "numItemsVisible" property for details.


int QListBox::numRows () const

Returns the number of rows in the list box 🌈. See the "numRows" property for details.


void QListBox::onItem ( QListBoxItem * i ) [signal]

This signal fires when the user moves the mouse cursor onto an item β€” very similar energy to the QWidget::enterEvent() function πŸ¦‹. i is the QListBoxItem that the mouse has moved on.


void QListBox::onViewport () [signal]

This signal fires when the user moves the mouse cursor from an item to an empty part of the list box 🌸. Leaving the item, entering the void, it's giving lonely.


void QListBox::paintCell ( QPainter * p, int row, int col ) [virtual protected]

Provided for compatibility with the old QListBox πŸ‘‘. We recommend using QListBoxItem::paint() instead, fr fr.

Repaints the cell at row, col using painter p 🎨.


const QPixmap * QListBox::pixmap ( int index ) const

Returns a pointer to the pixmap at position index, or 0 if there's no pixmap there πŸ™ˆ.

See also text().


void QListBox::pressed ( QListBoxItem * item ) [signal]

This signal fires when the user presses any mouse button πŸ’…. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

⚠️ You must not delete any QListBoxItem objects in slots connected to this signal πŸ’€.

void QListBox::pressed ( QListBoxItem * item, const QPoint & pnt ) [signal]

This is an overloaded member function, provided for convenience ✨. It behaves essentially like the above function.

This signal fires when the user presses any mouse button πŸ’–. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

pnt is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()) πŸ“.

⚠️ You must not delete any QListBoxItem objects in slots connected to this signal 😭.

See also mouseButtonPressed(), rightButtonPressed(), and clicked().


void QListBox::removeItem ( int index )

Removes and deletes the item at position index πŸ—‘οΈ. And bestie, listen: if index is equal to currentItem(), a new item becomes current and the currentChanged() and highlighted() signals get emitted πŸ“£.

See also insertItem() and clear().


void QListBox::returnPressed ( QListBoxItem * ) [signal]

This signal fires when Enter or Return is pressed ⏎. The argument is currentItem() ✨.


void QListBox::rightButtonClicked ( QListBoxItem *, const QPoint & ) [signal]

This signal fires when the right button is clicked β€” i.e. when it's released at the same point where it was pressed πŸ–±οΈ. The arguments are the relevant QListBoxItem (may be 0) and the point in global coordinates 🌍.


void QListBox::rightButtonPressed ( QListBoxItem *, const QPoint & ) [signal]

This signal fires when the right button is pressed πŸ‘†. The arguments are the relevant QListBoxItem (may be 0) and the point in global coordinates 🌍.


LayoutMode QListBox::rowMode () const

Returns the row layout mode for this list box πŸ“. See the "rowMode" property for details.


bool QListBox::scrollBar () const

⚠️ This function is obsolete. It's provided to keep old source working, and we strongly advise against using it in new code πŸ’€.

Returns FALSE if vScrollBarMode() is AlwaysOff; otherwise returns TRUE.


void QListBox::selectAll ( bool select ) [virtual slot]

In Multi and Extended modes, this function sets all items to be selected if select is TRUE, and to be unselected if select is FALSE πŸŽ€.

In Single and NoSelection modes, this function only changes the selection status of currentItem() β€” that's it, just the one ✨.


void QListBox::selected ( int index ) [signal]

This signal fires when the user double-clicks on an item, or presses Enter on the current item πŸ”₯. index is the index of the selected item.

See also currentChanged(), highlighted(), and selectionChanged().


void QListBox::selected ( const QString & ) [signal]

This is an overloaded member function, provided for convenience 🫢. It behaves essentially like the above function.

This signal fires when the user double-clicks on an item, or presses Enter on the current item, and the item is (or has) a string 🌸. The argument is the text of the selected item.

See also currentChanged(), highlighted(), and selectionChanged().


void QListBox::selected ( QListBoxItem * ) [signal]

This is an overloaded member function, provided for convenience πŸ’–. It behaves essentially like the above function.

This signal fires when the user double-clicks on an item, or presses Enter on the current item πŸ‘‘. The argument is a pointer to the new selected item.

See also currentChanged(), highlighted(), and selectionChanged().


QListBoxItem * QListBox::selectedItem () const

Returns the selected item β€” but only if the list box is in single-selection mode and an item is actually selected πŸ™ˆ.

If no items are selected, or the list box is in another selection mode, this function returns 0 πŸ’€.

See also setSelected() and multiSelection.


void QListBox::selectionChanged () [signal]

This signal fires when the selection set of a list box changes ✨. It fires in each selection mode. And here's the cute part: if the user selects five items by drag-selecting, QListBox tries to emit just one selectionChanged() signal, so you can connect it to computationally expensive slots without your app catching fire πŸ”₯. Iconic behaviour, honestly.

See also selected() and currentItem.


void QListBox::selectionChanged ( QListBoxItem * item ) [signal]

This is an overloaded member function, provided for convenience πŸŽ€. It behaves essentially like the above function.

This signal fires when the selection in a Single selection list box changes πŸ¦‹. item is the newly selected list box item.

See also selected() and currentItem.


SelectionMode QListBox::selectionMode () const

Returns the selection mode of the list box πŸ’…. See the "selectionMode" property for details.


void QListBox::setAutoBottomScrollBar ( bool enable )

⚠️ This function is obsolete. It's provided to keep old source working, and we strongly advise against using it in new code 😭.

If enable is TRUE, sets setHScrollBarMode() to AlwaysOn; otherwise sets setHScrollBarMode() to AlwaysOff 🎚️.


void QListBox::setAutoScrollBar ( bool enable )

⚠️ This function is obsolete. It's provided to keep old source working, and we strongly advise against using it in new code πŸ’€.

If enable is TRUE, sets setVScrollBarMode() to AlwaysOn; otherwise sets setVScrollBarMode() to AlwaysOff 🎚️.


void QListBox::setBottomItem ( int index ) [virtual]

Scrolls the list box so the item at position index in the list is displayed in the bottom row of the list box β¬‡οΈβœ¨.

See also topItem.


void QListBox::setBottomScrollBar ( bool enable )

⚠️ This function is obsolete. It's provided to keep old source working, and we strongly advise against using it in new code πŸ™ˆ.

If enable is TRUE, sets setHScrollBarMode() to AlwaysOn; otherwise sets setHScrollBarMode() to AlwaysOff 🎚️.


void QListBox::setColumnMode ( LayoutMode ) [virtual]

Sets the column layout mode for this list box πŸ“Š. See the "columnMode" property for details.


void QListBox::setColumnMode ( int ) [virtual]

Sets the column layout mode for this list box πŸ“Š. See the "columnMode" property for details.


void QListBox::setCurrentItem ( int index ) [virtual]

Sets the current highlighted item to index πŸ‘‘βœ¨. See the "currentItem" property for details.

void QListBox::setCurrentItem ( QListBoxItem * i ) [virtual]

okay so this one is an overloaded member function, there for convenience, and it behaves essentially like the one above it πŸ’«

It sets the current item to the QListBoxItem i. That's it, that's the whole vibe.


void QListBox::setMultiSelection ( bool multi )

Sets whether or not the list box is in Multi selection mode to multi. See the "multiSelection" property for details, bestie ✨


void QListBox::setRowMode ( LayoutMode ) [virtual]

Sets the row layout mode for this list box. See the "rowMode" property for details πŸŽ€


void QListBox::setRowMode ( int ) [virtual]

Another one! Sets the row layout mode for this list box. See the "rowMode" property for details. Same energy, different signature πŸ’…


void QListBox::setScrollBar ( bool enable )

⚠️ This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. Like, do not, fr fr. πŸ™ˆ

If enable is TRUE sets setVScrollBarMode() to AlwaysOn; otherwise sets setVScrollBarMode() to AlwaysOff.


void QListBox::setSelected ( QListBoxItem * item, bool select ) [virtual]

Selects item if select is TRUE or unselects it if select is FALSE, and repaints the item appropriately ✨

If the list box is a Single selection list box and select is TRUE, setSelected() calls setCurrentItem().

If the list box is a Single selection list box, select is FALSE, setSelected() calls clearSelection().

See also multiSelection, currentItem, clearSelection(), and currentItem. (yes it says currentItem twice, that's the original's business, not mine 🫢)


void QListBox::setSelected ( int index, bool select )

Overloaded member function, provided for convenience, behaves essentially like the above function πŸ’«

If select is TRUE the item at position index is selected; otherwise the item is deselected.


void QListBox::setSelectionMode ( SelectionMode ) [virtual]

Sets the selection mode of the list box. See the "selectionMode" property for details 🌸


void QListBox::setTopItem ( int index ) [virtual]

Sets the index of an item at the top of the screen to index. See the "topItem" property for details ✨


void QListBox::setVariableHeight ( bool ) [virtual]

Sets whether this list box has variable-height rows. See the "variableHeight" property for details πŸŽ€


void QListBox::setVariableWidth ( bool ) [virtual]

Sets whether this list box has variable-width columns. See the "variableWidth" property for details 🌈


void QListBox::sort ( bool ascending = TRUE )

If ascending is TRUE sorts the items in ascending order; otherwise sorts in descending order πŸ”₯

To compare the items, the text (QListBoxItem::text()) of the items is used.

Example: listbox/listbox.cpp.


void QListBox::takeItem ( const QListBoxItem * item )

Removes item from the list box and causes an update of the screen display. The item is not deleted. You should normally not need to call this function because QListBoxItem::~QListBoxItem() calls it. The normal way to delete an item is with delete. πŸ‘‘

See also QListBox::insertItem().


QString QListBox::text ( int index ) const

Returns the text at position index, or QString::null if there is no text at that position 😭

See also pixmap().


void QListBox::toggleCurrentItem () [protected]

Toggles the selection status of currentItem() and repaints if the list box is a Multi selection list box. πŸ’…

See also multiSelection.


int QListBox::topItem () const

Returns the index of an item at the top of the screen. See the "topItem" property for details ✨


int QListBox::totalHeight () const [protected]

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

Returns contentsHeight().


int QListBox::totalWidth () const [protected]

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

Returns contentsWidth().


void QListBox::triggerUpdate ( bool doLayout )

Ensures that a single paint event will occur at the end of the current event loop iteration. If doLayout is TRUE, the layout is also redone. Efficiency queen πŸ‘‘


void QListBox::updateItem ( int index ) [protected]

Repaints the item at position index in the list πŸŽ€


void QListBox::updateItem ( QListBoxItem * i ) [protected]

Overloaded member function, provided for convenience, behaves essentially like the above function ✨

Repaints the QListBoxItem i.


bool QListBox::variableHeight () const

Returns TRUE if this list box has variable-height rows; otherwise returns FALSE. See the "variableHeight" property for details 🌸


bool QListBox::variableWidth () const

Returns TRUE if this list box has variable-width columns; otherwise returns FALSE. See the "variableWidth" property for details 🌈


πŸŽ€ Property Documentation πŸŽ€

LayoutMode columnMode

This property holds the column layout mode for this list box.

setColumnMode() sets the layout mode and adjusts the number of displayed columns. The row layout mode automatically becomes Variable, unless the column mode is Variable.

See also rowMode, rowMode, and numColumns. (yes, rowMode is listed twice, iconic of it honestly πŸ’…)

Set this property's value with setColumnMode() and get this property's value with columnMode().


uint count

This property holds the number of items in the list box.

Get this property's value with count().


int currentItem

This property holds the current highlighted item.

When setting this property, the highlighting is moved to the item and the list box scrolled as necessary ✨

If no item is current, currentItem() returns -1.

Set this property's value with setCurrentItem() and get this property's value with currentItem().


QString currentText

This property holds the text of the current item.

This is equivalent to text(currentItem()).

Get this property's value with currentText().


bool multiSelection

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

This property holds whether or not the list box is in Multi selection mode.

Consider using the QListBox::selectionMode property instead of this property, bestie, it's the glow-up version 🫢

When setting this property, Multi selection mode is used if set to TRUE and to Single selection mode if set to FALSE.

When getting this property, TRUE is returned if the list box is in Multi selection mode or Extended selection mode, and FALSE if it is in Single selection mode or NoSelection mode.

See also selectionMode.

Set this property's value with setMultiSelection() and get this property's value with isMultiSelection().


int numColumns

This property holds the number of columns in the list box.

This is normally 1, but can be different if QListBox::columnMode or QListBox::rowMode has been set.

See also columnMode, rowMode, and numRows.

Get this property's value with numColumns().


int numItemsVisible

This property holds the number of visible items.

Both partially and entirely visible items are counted. πŸ‘€

Get this property's value with numItemsVisible().


int numRows

This property holds the number of rows in the list box.

This is equal to the number of items in the default single-column layout, but can be different.

See also columnMode, rowMode, and numColumns.

Get this property's value with numRows().


LayoutMode rowMode

This property holds the row layout mode for this list box.

This property is normally Variable.

setRowMode() sets the layout mode and adjusts the number of displayed rows. The column layout mode automatically becomes Variable, unless the row mode is Variable.

See also columnMode.

Set this property's value with setRowMode() and get this property's value with rowMode().


SelectionMode selectionMode

This property holds the selection mode of the list box.

Sets the list box's selection mode, which may be one of Single (the default), Extended, Multi or NoSelection. Pick your fighter πŸ’…

See also SelectionMode.

Set this property's value with setSelectionMode() and get this property's value with selectionMode().


int topItem

This property holds the index of an item at the top of the screen.

When getting this property and the listbox has multiple columns, an arbitrary item is selected and returned. 🎲

When setting this property, the list box is scrolled so the item at position index in the list is displayed in the top row of the list box.

Set this property's value with setTopItem() and get this property's value with topItem().


bool variableHeight

This property holds whether this list box has variable-height rows.

When the list box has variable-height rows (the default), each row is as high as the highest item in that row. When it has same-sized rows, all rows are as high as the highest item in the list box. Tallest item stays winning πŸ‘‘

See also variableWidth.

Set this property's value with setVariableHeight() and get this property's value with variableHeight().


bool variableWidth

This property holds whether this list box has variable-width columns.

When the list box has variable-width columns, each column is as wide as the widest item in that column. When it has same-sized columns (the default), all columns are as wide as the widest item in the list box. Widest item is the main character here 🌈

See also variableHeight.

Set this property's value with setVariableWidth() and get this property's value with variableWidth().


🌟 SEE ALSO 🌟


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


✨ AUTHOR ✨

Generated automatically from the source code. (no human author, just vibes and a build script 🫢)


πŸ¦‹ BUGS πŸ¦‹

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. πŸ’œ

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qlistbox.3qt) and the Qt version (3.3.8).


okay bestie that's the whole page, we made it, and it came from Trolltech AS, dated 2 February 2007, sitting under the QListBox(3qt) title πŸ’…βœ¨ periodt, go forth and build ur little list boxes πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from