📄 qlistbox.3qt
字号:
.BI "void \fBonItem\fR ( QListBoxItem * item ) ".br.ti -1c.BI "void \fBonViewport\fR () ".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "void \fBupdateItem\fR ( int index ) ".br.ti -1c.BI "void \fBupdateItem\fR ( QListBoxItem * ) ".br.ti -1c.BI "virtual void \fBpaintCell\fR ( QPainter *, int " "row" ", int col ) ".br.ti -1c.BI "void \fBtoggleCurrentItem\fR () ".br.ti -1c.BI "bool \fBisRubberSelecting\fR () const".br.ti -1c.BI "void \fBdoLayout\fR () const".br.in -1c.SS "Protected Slots".in +1c.ti -1c.BI "void \fBclearInputString\fR () (internal)".br.in -1c.SS "Properties"<table border=1 cellpadding=3 cellspacing=0> <tr><th>Type<th>Name<th>READ<th>WRITE<th>Options <tr><td>uint<td>count<td>count<td> <td> <tr><td>int<td>numItemsVisible<td>numItemsVisible<td> <td> <tr><td>int<td>currentItem<td>currentItem<td>setCurrentItem<td> DESIGNABLE false <tr><td>QString<td>currentText<td>currentText<td> <td> <tr><td>int<td>topItem<td>topItem<td>setTopItem<td> DESIGNABLE false <tr><td>SelectionMode<td>selectionMode<td>selectionMode<td>setSelectionMode<td> <tr><td>bool<td>multiSelection<td>isMultiSelection<td>setMultiSelection<td> DESIGNABLE false <tr><td>LayoutMode<td>columnMode<td>columnMode<td>setColumnMode<td> <tr><td>LayoutMode<td>rowMode<td>rowMode<td>setRowMode<td> <tr><td>int<td>numColumns<td>numColumns<td> <td> <tr><td>int<td>numRows<td>numRows<td> <td> <tr><td>bool<td>variableWidth<td>variableWidth<td>setVariableWidth<td> <tr><td>bool<td>variableHeight<td>variableHeight<td>setVariableHeight<td> </table>.SH DESCRIPTIONThe QListBox widget provides a list of selectable, read-only items..PPThis is typically a single-column list where zero or one items are selected at once, but can also be used in many other ways..PPQListBox will add scroll bars as necessary, but isn't intended for \fIreally\fR big lists. If you want more than a few thousand items, it's probably better to use a different widget, chiefly because the scroll bars won't provide very good navigation, but also because QListBox may become slow at larger sizes..PPThere is a variety of selection modes, described in the QListBox::SelectionMode documentation. The default is single-selection, and you can change it using setSelectionMode(). For compatibility with previous Qt versions there is still the setMultiSelection() methode. Calling setMultiSelection( TRUE ) is equivalent to setSelectionMode( Multi ), and setMultiSelection( FALSE ) is equivalent to setSelectionMode( Single ). It's suggested not to use setMultiSelection() anymore, but to use setSelectionMode() instead..PPSince QListBox offers multiple selection it has to display keyboard focus and selection state separately. Therefore there are functions both to set the selection state of an item, setSelected(), and to select which item displays keyboard focus, setCurrentItem()..PPThe list box normally arranges its items in a single column with a vertical scroll bar if necessary, but it is also possible to have a different fixed number of columns (setColumnMode()), or as many columns as will fit in the list box' assigned screen space (setColumnMode( FitToWidth )), or to have a fixed number of rows (setRowMode()), or as many rows as will fit in the list box' assigned screen space (setRowMode( FitToHeight )). In all these cases, QListBox will add scroll bars as appropriate in at least one direction..PPIf multiple rows is 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 ). Of course there is a similar setVariableWidth()..PPThe items discussed are QListBoxItem objects. QListBox provides methods to insert new items as a string, 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 (surprise: removeItem()) and clear() the entire list box. Note that if you create a QListBoxItem yourself and insert it, it becomes the property of QListBox and you may not delete it. (QListBox will delete it when appropriate.).PPYou can also create a QListBoxItem such as QListBoxText or QListBoxPixmap with the list box as first parameter. The item will then append itself. When you delete an item, it is automatically removed from the listbox..PPThe list of items can be arbitrarily big; if necessary, QListBox adds scroll bars. It can be single-column (as most list boxes are) or multi-column, and offers both single and multiple selection. (QListBox does however not support multiple-column items; QListView does that job.) Also a listbox can display items arranged in a tree. But this is quite limited, and if you really want to display and work with a tree, you should use a QListView. The tree stuff in the QListBox is only supported because it磗 needed in comboboxes..PPThe 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; most things can be done using the indexes too but unfortunately not everything..PPEach item in a QListBox contains a QListBoxItem. One of the items can be the current item. The highlighted() signal is emitted when a new item gets highlighted, 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 return when an item is highlighted..PPIf the user does not select anything, no signals are emitted and currentItem() returns -1..PPA list box has \fCWheelFocus\fR as a default focusPolicy(), i.e. it can get keyboard focus both by tabbing, clicking and the mouse wheel..PPNew items may be inserted using either insertItem(), insertStrList() or insertStringList(). inSort() is obsolete, as this method is quite inefficient. It's preferable to insert the items normally and call sort() afterwards, or insert a sorted QStringList()..PPBy default, vertical and horizontal scroll bars are added and removed as necessary. setHScrollBarMode() and setVScrollBarMode() can be used to change this policy..PPIf you need to insert other types than texts and pixmaps, you must define new classes which inherit QListBoxItem..PP\fBWarning:\fR The list box assumes ownership of all list box items and will delete them when it does not need them any more..PP<img src=qlistbox-m.png> <img src=qlistbox-w.png>.PPSee also QListView, QComboBox, QButtonGroup and GUI Design Handbook: List Box (two sections).SS "Member Type Documentation".SH "QListBox::LayoutMode"This enum type decides how QListBox lays out its rows and columns. The two modes interact, of course..PPThe possible values for each mode are: .TP\fCFixedNumber\fR - there is a fixed number of rows (or columns)..TP\fCFitToHeight\fR - there are as many rows as will fit on-screen. (Ditto with \fCFitToWidth\fR and columns.).TP\fCVariable\fR - there are as many rows as are required by the column mode. (Or as many columns as required by the row mode.).IP.PPExample: When you call setRowMode( FitToHeight ), columnMode() automatically becomes \fCVariable\fR to accomodate the row mode you've set..SH "QListBox::SelectionMode"This enumerated type is used by QListBox to indicate how it reacts to selection by the user. It has four values: .TP\fCSingle\fR - 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()..TP\fCMulti\fR - When the user selects an item in the most ordinary way, the selection status of that item is toggled and the other items are left alone..TP\fCExtended\fR - When the user selects an item in the most ordinary way, 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 stayes pressed..TP\fCNoSelection\fR - Items cannot be selected..IP.PPIn other words, \fCSingle\fR is a real single-selection list box, \fCMulti\fR a real multi-selection list box, and \fCExtended\fR list box where users can select multiple items but usually want to select either just one or a range of contiguous items, and \fCNoSelection\fR is for a list box where the user can look but not touch..SH MEMBER FUNCTION DOCUMENTATION.SH "QListBox::QListBox ( QWidget * parent=0, const char * name=0, WFlags f=0 )"Constructs a new empty list box, with \fIparent\fR as a parent and \fIname\fR as object name..PPPerformance is boosted by modifying the widget flags \fIf\fR so that only part of the QListBoxItem children is redrawn. This may be unsuitable for custom QListBoxItem classes, in which case \fCWNorthWestGravity\fR and \fCWRepaintNoErase\fR should be cleared..PPSee also QWidget::clearWFlags() and Qt::WidgetFlags..SH "QListBox::~QListBox ()"Destroys the list box. Deletes all list box items..SH "void QListBox::centerCurrentItem ()"If there is a current item, the listbox is scrolled, so that this item is displayed centered..PPSee also QListBox::ensureCurrentVisible()..SH "void QListBox::changeItem ( const QListBoxItem * lbi, int index )"Replaces the item at position \fIindex\fR with \fIlbi.\fR If \fIindex\fR is negative or too large, changeItem() does nothing..PPSee also insertItem() and removeItem()..SH "void QListBox::changeItem ( const QPixmap & pixmap, const QString & text, int index )"Replaces the item at position \fIindex\fR with \fIpixmap\fR and \fItext.\fR.PPThe operation is ignored if \fIindex\fR is out of range..PPSee also insertItem() and removeItem()..SH "void QListBox::changeItem ( const QPixmap & pixmap, int index )"Replaces the item at position \fIindex\fR with \fIpixmap.\fR.PPThe operation is ignored if \fIindex\fR is out of range..PPSee also insertItem() and removeItem()..SH "void QListBox::changeItem ( const QString & text, int index )"Replaces the item at position \fIindex\fR with \fItext.\fR.PPThe operation is ignored if \fIindex\fR is out of range..PPSee also insertItem() and removeItem()..SH "void QListBox::clear ()"Deletes all items in the list..PPSee also removeItem()..SH "void QListBox::clearSelection () \fC[virtual slot]\fR"Deselects all items, if possible..PPNote that a single-selection listbox will automatically select an item if it has keyboard focus..SH "void QListBox::clicked ( QListBoxItem * item ) \fC[signal]\fR"This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listbox. \fIitem\fR is the pointer to the clicked listbox item or NULL, if the user didn't click on an item..PPNote that you may not delete any QListBoxItem objects in slots connected to this signal..SH "void QListBox::clicked ( QListBoxItem * item, const QPoint & pnt ) \fC[signal]\fR"This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listbox. \fIitem\fR is the pointer to the clicked listbox item or NULL, if the user didn't click on an item. \fIpnt\fR is the position where the user has clicked..PPNote that you may not delete any QListBoxItem objects in slots connected to this signal..SH "QListBox::LayoutMode QListBox::columnMode() const"Returns the column layout mode for this list box. This is normally \fCFixedNumber,\fR but can be changed by calling setColumnMode().PPSee also rowMode(), setColumnMode() and numColumns()..SH "uint QListBox::count () const"Returns the number of items in the list box..SH "void QListBox::currentChanged ( QListBoxItem * item ) \fC[signal]\fR"This signal is emitted when the user highlights a new current item. The argument is the index of the new item, which is already current..PPSee also setCurrentItem() and currentItem()..SH "int QListBox::currentItem () const"Returns the index of the current (highlighted) item of the list box, or -1 if no item has been selected..PPSee also topItem()..SH "QString QListBox::currentText () const"Returns the text of the current item..PPThis is equivalent to text(currentItem())..SH "void QListBox::doLayout () const \fC[protected]\fR"This function does the hard layout work. You should never need to call it..SH "void QListBox::doubleClicked ( QListBoxItem * item ) \fC[signal]\fR"This signal is emitted whenever an item is double-clicked. It's emitted on the second button press, not the second button release. \fIitem\fR is the listbox item onto which the user did the double click..SH "void QListBox::ensureCurrentVisible () \fC[virtual slot]\fR"Ensures that the current item is visible..SH "QListBoxItem * QListBox::findItem ( const QString & text ) const"Finds the first listbox item which starts with \fItext\fR and returns it, or returns 0 of no such item could be found. The search is done case-insensitive..SH "QListBoxItem * QListBox::firstItem () const"Returns the first item of this listbox..SH "void QListBox::focusInEvent ( QFocusEvent * e ) \fC[virtual protected]\fR"Reimplemented for internal reasons; the API is not affected..PPReimplemented from QWidget..SH "void QListBox::focusOutEvent ( QFocusEvent * ) \fC[virtual protected]\fR"Reimplemented for internal reasons; the API is not affected..PPReimplemented from QWidget..SH "void QListBox::highlighted ( QListBoxItem * ) \fC[signal]\fR"This signal is emitted when the user highlights a new current item. The argument is a pointer to the new current item..PPSee also selected(), currentItem() and selectionChanged()..SH "void QListBox::highlighted ( const QString & ) \fC[signal]\fR"This signal is emitted when the user highlights a new current item and the new item is a string. The argument is the text of the new current item..PPSee also selected(), currentItem() and selectionChanged()..SH "void QListBox::highlighted ( int index ) \fC[signal]\fR"This signal is emitted when the user highlights a new current item. The argument is the index of the new item, which is already current..PPSee also selected(), currentItem() and selectionChanged()..SH "int QListBox::index ( const QListBoxItem * lbi ) const"Returns the index of \fIlbi,\fR or -1 if the item is not in this list box or \fIlbi\fR is a NULL-Pointer..PPSee also item()..SH "void QListBox::insertItem ( const QListBoxItem * lbi, const QListBoxItem * after )"Inserts the item \fIlbi\fR into the list after the item \fIafter.\fR.PPIf \fIafter\fR is NULL, \fIlbi\fR is inserted at the beginning..PPSee also insertStrList()..SH "void QListBox::insertItem ( const QListBoxItem * lbi, int index=-1 )"Inserts the item \fIlbi\fR into the list at \fIindex.\fR.PPIf \fIindex\fR is negative or larger than the number of items in the list box, \fIlbi\fR is inserted at the end of the list..PPSee also insertStrList()..SH "void QListBox::insertItem ( const QPixmap & pixmap, const QString & text, int index=-1 )"Inserts \fIpixmap\fR and \fItext\fR into the list at \fIindex.\fR.PPIf \fIindex\fR is negative, \fIpixmap\fR is inserted at the end of the list..PPSee also insertStrList()..SH "void QListBox::insertItem ( const QPixmap & pixmap, int index=-1 )"Inserts \fIpixmap\fR into the list at \fIindex.\fR.PPIf \fIindex\fR is negative, \fIpixmap\fR is inserted at the end of the list..PPSee also insertStrList()..SH "void QListBox::insertItem ( const QString & text, int index=-1 )"Inserts \fItext\fR into the list at \fIindex.\fR.PPIf \fIindex\fR is negative, \fItext\fR is inserted at the end of the list..PPSee also insertStrList()..SH "void QListBox::insertStrList ( const QStrList & list, int index=-1 )"Inserts the string list \fIlist\fR into the list at item \fIindex.\fR.PPIf \fIindex\fR is negative, \fIlist\fR is inserted at the end of the list. If \fIindex\fR is too large, the operation is ignored..PP\fBWarning:\fR This function uses \fCconst char *\fR 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() - it uses real QStrings..PP\fBWarning:\fR This function is never significantly faster than a loop around insertItem()..PPSee also insertItem() and insertStringList()..SH "void QListBox::insertStrList ( const QStrList * list, int index=-1 )"Inserts the string list \fIlist\fR into the list at item \fIindex.\fR.PPIf \fIindex\fR is negative, \fIlist\fR is inserted at the end of the list. If \fIindex\fR is too large, the operation is ignored..PP\fBWarning:\fR This function uses \fCconst char *\fR 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() - it uses real QStrings..PP\fBWarning:\fR This function is never significantly faster than a loop around insertItem()..PPSee also insertItem() and insertStringList()..SH "void QListBox::insertStrList ( const char ** strings, int numStrings=-1, int index=-1 )"Inserts the \fInumStrings\fR strings of the array \fIstrings\fR into the list at item\fIindex.\fR.PPIf \fIindex\fR is negative, insertStrList() inserts \fIstrings\fR at the end of the list. If \fIindex\fR is too large, the operation is ignored..PP\fBWarning:\fR This function uses \fCconst char *\fR 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() - it uses real QStrings..PP\fBWarning:\fR This function is never significantly faster than a loop around insertItem()..PPSee also insertItem() and insertStringList()..SH "void QListBox::insertStringList ( const QStringList & list, int index=-1 )"Inserts the string list \fIlist\fR into the list at item \fIindex.\fR.PPIf \fIindex\fR is negative, \fIlist\fR is inserted at the end of the list. If \fIindex\fR is too large, the operation is ignored..PP\fBWarning:\fR This function is never significantly faster than a loop around insertItem()..PPSee also insertItem() and insertStrList()..SH "void QListBox::invertSelection () \fC[slot]\fR"Inverts the selection. Works only in Multi and Extended selection mode..SH "bool QListBox::isMultiSelection () const"\fBThis function is obsolete.\fR It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code..PPConsider using selectionMode() instead of this method..PPReturns TRUE if the listbox is in multi-selection mode or extended selection mode, and FALSE if it is in single-selection mode or no-selection more..PPSee also selectionMode() and setSelectionMode()..SH "bool QListBox::isRubberSelecting () const \fC[protected]\fR"Returns whether the user is selecting items using a rubber rectangle..SH "bool QListBox::isSelected ( const QListBoxItem * i ) const"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -