📄 qlistview.3qt
字号:
.ti -1c.BI "void \fBupdateContents\fR () ".br.ti -1c.BI "void \fBdoAutoScroll\fR () ".br.in -1c.SS "Properties".nf.TSl l l l l- - - - -l l l l l.Type Name READ WRITE Optionsint columns columnsbool multiSelection isMultiSelection setMultiSelection DESIGNABLE falseSelectionMode selectionMode selectionMode setSelectionModeint childCount childCountbool allColumnsShowFocus allColumnsShowFocus setAllColumnsShowFocusbool showSortIndicator showSortIndicator setShowSortIndicatorint itemMargin itemMargin setItemMarginbool rootIsDecorated rootIsDecorated setRootIsDecorated.TE.fi.SH DESCRIPTIONThe QListView class implements a list/tree view..PPIt can display and control a hierarchy of multi-column items, and provides the ability to add new items at any time, let the user select one or many items, sort the list in increasing or decreasing order by any column, and so on..PPThe simplest mode of usage is to create a QListView, add some column headers using addColumn(), create one or more QListViewItem objects with the QListView as parent, set up the list view's geometry(), and show() it..PPThe main setup functions are .TPaddColumn() - adds a column, with text and perhaps width..TPsetColumnWidthMode() - sets the column to be resized automatically or not..TPsetAllColumnsShowFocus() - decides whether items should show keyboard focus using all columns, or just column 0. The default is to show focus using just column 0..TPsetRootIsDecorated() - decides whether root items can be opened and closed by the user, and have open/close decoration to their left. The default is FALSE..TPsetTreeStepSize() - decides the how many pixels an item's children are indented relative to their parent. The default is 20. This is mostly a matter of taste..TPsetSorting() - decides whether the items should be sorted, whether it should be in ascending or descending order, and by what column it should be sorted..PPTo handle events such as mouse-presses on the listview, derived classes can reimplement the QScrollView functions contentsMousePressEvent, contentsMouseReleaseEvent, contentsMouseDoubleClickEvent, contentsMouseMoveEvent, contentsDragEnterEvent, contentsDragMoveEvent, contentsDragLeaveEvent, contentsDropEvent, and contentsWheelEvent..PPThere are also several functions for mapping between items and coordinates. itemAt() returns the item at a position on-screen, itemRect() returns the rectangle an item occupies on the screen and itemPos() returns the position of any item (not on-screen, in the list view). firstChild() returns the item at the top of the view (not necessarily on-screen) so you can iterate over the items using either QListViewItem::itemBelow() or a combination of QListViewItem::firstChild() and QListViewItem::nextSibling()..PPNaturally, QListView provides a clear() function, as well as an explicit insertItem() for when QListViewItem's default insertion won't do..PPThere is a variety of selection modes, described in the QListView::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 QListView 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()..PPQListView emits two groups of signals: One group signals changes in selection/focus state and one signals selection. The first group consists of selectionChanged(), applicable to all list views, and selectionChanged( QListViewItem * ), applicable only to single-selection list view, and currentChanged( QListViewItem * ). The second group consists of doubleClicked( QListViewItem * ), returnPressed( QListViewItem * ) and rightButtonClicked( QListViewItem *, const QPoint&, int ), etc..PPIn Motif style, QListView deviates fairly strongly from the look and feel of the Motif hierarchical tree view. This is done mostly to provide a usable keyboard interface and to make the list view look better with a white background..PP\fBWarning:\fR The list view assumes ownership of all list view items and will delete them when it does not need them any more..PP.ce 1.B "[Image Omitted]".PP.ce 1.B "[Image Omitted]".PPExamples:.(lxml/tagreader.)l-with-features/tagreader.cpp.SS "Member Type Documentation".SH "QListView::SelectionMode"This enumerated type is used by QListView 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 QListView::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 listview, \fCMulti\fR a real multi-selection listview, and \fCExtended\fR listview 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 listview where the user can look but not touch..SH "QListView::WidthMode"This enum type describes how the width of a column in the view changes. The currently defined modes are: .TP\fCManual\fR - the column width does not change automatically.TP\fCMaximum\fR - the column is automatically sized according to the widths of all items in the column. (Note: The column never shrinks in this case.) This means the column is always resized to the width of the item with the largest width in the column..IP.PPSee also setColumnWidth(), setColumnWidthMode() and columnWidth()..SH MEMBER FUNCTION DOCUMENTATION.SH "QListView::QListView ( QWidget * parent = 0, const char * name = 0 )"Constructs a new empty list view, with \fIparent\fR as a parent and \fIname\fR as object name..PPPerformance is boosted by modifying the widget flags so that only part of the QListViewItem children is redrawn. This may be unsuitable for custom QListViewItem classes, in which case \fCWNorthWestGravity\fR and \fCWRepaintNoErase\fR should be cleared..PPSee also QWidget::clearWFlags() and Qt::WidgetFlags..SH "QListView::QListView ( QWidget * parent, const char * name, WFlags f )"Constructs a new empty list view, 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 QListViewItem children is redrawn. This may be unsuitable for custom QListViewItem classes, in which case \fCWNorthWestGravity\fR and \fCWRepaintNoErase\fR should be cleared..PPSee also QWidget::clearWFlags() and Qt::WidgetFlags..SH "QListView::~QListView ()"Destructs the listview, deleting all items in it, and frees up all allocated resources..SH "int QListView::addColumn ( const QIconSet & iconset, const QString & label, int width = -1 ) \fC[virtual]\fR"Adds a new column at the right end of the widget, with the header \fIlabel\fR and \fIiconset,\fR and returns the index of the column..PPIf \fIwidth\fR is negative, the new column will have WidthMode Maximum, otherwise it will be Manual at \fIwidth\fR pixels wide..PPSee also setColumnText(), setColumnWidth() and setColumnWidthMode()..SH "int QListView::addColumn ( const QString & label, int width = -1 ) \fC[virtual]\fR"Adds a new column at the right end of the widget, with the header \fIlabel,\fR and returns the index of the column..PPIf \fIwidth\fR is negative, the new column will have WidthMode Maximum, otherwise it will be Manual at \fIwidth\fR pixels wide..PPSee also setColumnText(), setColumnWidth() and setColumnWidthMode()..PPExamples:.(ldirview/main.cpp.)l.SH "bool QListView::allColumnsShowFocus () const"Returns TRUE if the items in this list view indicate focus and selection state using all of their columns, else FALSE..PPSee also setAllColumnsShowFocus()..SH "int QListView::childCount () const"Returns the current number of parentless QListViewItem objects in this QListView, like QListViewItem::childCount() returns the number of child items for a QListViewItem..PPSee also QListViewItem::childCount()..SH "void QListView::clear () \fC[virtual]\fR"Remove and delete all the items in this list view, and trigger an update..PPSee also triggerUpdate()..SH "void QListView::clearSelection () \fC[virtual]\fR"Sets all items to be not selected, updates the list view as necessary and emits the selectionChanged() signals. Note that for multi-selection list views, this function needs to iterate over \fIall\fR items..PPSee also setSelected() and setMultiSelection()..SH "void QListView::clicked ( QListViewItem * item ) \fC[signal]\fR"This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listview. \fIitem\fR is the pointer to the clicked listview item or NULL, if the user didn't click on an item..PPNote that you may not delete any QListViewItem objects in slots connected to this signal..SH "void QListView::clicked ( QListViewItem * item, const QPoint & pnt, int c ) \fC[signal]\fR"This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listview. \fIitem\fR is the pointer to the clicked listview item or NULL, if the user didn't click on an item. \fIpnt\fR is the position where the user has clicked, and \fIc\fR the column into which the user clicked..PPNote that you may not delete any QListViewItem objects in slots connected to this signal..SH "void QListView::collapsed ( QListViewItem * item ) \fC[signal]\fR"This signals is emitted when the \fIitem\fR has been collapsed. This means the children of the item are hidden because the user double-clicked the item or clicked on the root decoration, or setOpen() with FALSE as argument has been called..PPSee also expanded()..SH "int QListView::columnAlignment ( int column ) const"Returns the alignment of logical column \fIcolumn.\fR The default is \fCAlignLeft.\fR.PPSee also Qt::AlignmentFlags..SH "QString QListView::columnText ( int c ) const"Returns the text of column \fIc.\fR.SH "int QListView::columnWidth ( int c ) const"Returns the width of column \fIc.\fR.SH "QListView::WidthMode QListView::columnWidthMode( int c ) const"Returns the currently set WidthMode for column \fIc.\fR.PPSee also setColumnWidthMode()..SH "int QListView::columns () const"Returns the number of columns of this list view..PPSee also addColumn() and removeColumn()..SH "void QListView::contentsMouseDoubleClickEvent ( QMouseEvent * e ) \fC[virtual protected]\fR"Processes mouse double-click events on behalf of the viewed widget..PPReimplemented from QScrollView..SH "void QListView::contentsMouseMoveEvent ( QMouseEvent * e ) \fC[virtual protected]\fR"Processes mouse move events on behalf of the viewed widget..PPReimplemented from QScrollView..SH "void QListView::contentsMousePressEvent ( QMouseEvent * e ) \fC[virtual protected]\fR"Processes mouse move events on behalf of the viewed widget..PPReimplemented from QScrollView..SH "void QListView::contentsMouseReleaseEvent ( QMouseEvent * e ) \fC[virtual protected]\fR"Processes mouse move events on behalf of the viewed widget..PPReimplemented from QScrollView..SH "void QListView::currentChanged ( QListViewItem * ) \fC[signal]\fR"This signal is emitted whenever the current item has changed (normally after the screen update). The current item is the item responsible for indicating keyboard focus..PPThe argument is the newly current item, or 0 if the change was to make no item current. This can happen e.g. if all items in the list view are deleted..PPNote that you may not delete any QListViewItem objects in slots connected to this signal..PPSee also setCurrentItem() and currentItem()..SH "QListViewItem * QListView::currentItem () const"Returns a pointer to the currently highlighted item, or 0 if there isn't any..PPSee also setCurrentItem()..SH "void QListView::doAutoScroll () \fC[protected slot]\fR"This slot handles auto-scrolling when the mouse button is pressed and the mouse is outside the widget..SH "void QListView::doubleClicked ( QListViewItem * 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 listview item onto which the user did the double click..SH "void QListView::drawContentsOffset ( QPainter * p, int ox, int oy, int cx, int cy, int cw, int ch ) \fC[virtual protected]\fR"Calls QListViewItem::paintCell() and/or QListViewItem::paintBranches() for all list view items that require repainting. See the documentation for those functions for details..PPReimplemented from QScrollView..SH "void QListView::enabledChange ( bool e ) \fC[virtual protected]\fR"Reimplemented for internal reasons; the API is not affected..PPReimplemented from QWidget..SH "void QListView::ensureItemVisible ( const QListViewItem * i )"Ensures that \fIi\fR is made visible, scrolling the list view vertically as required and opens (expands)also all parent items if they hide their children..PPSee also itemRect() and QScrollView::ensureVisible()..SH "bool QListView::eventFilter ( QObject * o, QEvent * e ) \fC[virtual]\fR"Redirects events for the viewport to mousePressEvent(), keyPressEvent() and friends..PPReimplemented from QObject..SH "void QListView::expanded ( QListViewItem * item ) \fC[signal]\fR"This signals is emitted when the \fIitem\fR has been expanded. This means the children of the item are shown because the user double-clicked the item or clicked on the root decoration, or setOpen() with TRUE as argument has been called..PPSee also collapsed()..SH "QListViewItem * QListView::firstChild () const"Returns the first item in this QListView. You can use its firstChild() and nextSibling() functions to traverse the entire tree of items..PPReturns 0 if there is no first item..PPSee also itemAt(), QListViewItem::itemBelow() and QListViewItem::itemAbove()..SH "void QListView::focusInEvent ( QFocusEvent * e ) \fC[virtual protected]\fR"Reimplemented for internal reasons; the API is not affected..PPReimplemented from QWidget..SH "void QListView::focusOutEvent ( QFocusEvent * ) \fC[virtual protected]\fR"Reimplemented for internal reasons; the API is not affected..PPReimplemented from QWidget..SH "QHeader * QListView::header () const"Returns a pointer to the QHeader object that manages this list view's columns. Please don't modify the header behind the list view's back..PPAcceptable methods to call are:.TPvoid QHeader::setClickEnabled( bool, int logIdx = -1 );.TPvoid QHeader::setResizeEnabled( bool, int logIdx = -1 );.TPvoid QHeader::setMovingEnabled( bool );.SH "void QListView::insertItem ( QListViewItem * i ) \fC[virtual]\fR"Inserts \fIi\fR into the list view as a top-level item. You do not need to call this unless you've called takeItem( \fIi\fR ) or QListViewItem::takeItem( i ) and need to reinsert \fIi\fR elsewhere..PPSee also QListViewItem::takeItem(), (important) and takeItem()..SH "void QListView::invertSelection () \fC[slot]\fR"Inverts the selection. Works only in Multi and Extended selection mode..SH "bool QListView::isMultiSelection () const"Returns TRUE if this list view is in multi-selection mode and FALSE if it is in single-selection mode..PPSee also setMultiSelection()..SH "bool QListView::isOpen ( const QListViewItem * item ) const"Identical to item->isOpen(). Provided for completeness..PPSee also setOpen()..SH "bool QListView::isSelected ( const QListViewItem * i ) const"Returns i->isSelected()..PPProvided only because QListView provides setSelected() and trolls are neat creatures and like neat, orthogonal interfaces..SH "QListViewItem * QListView::itemAt ( const QPoint & viewPos ) const"Returns a pointer to the QListViewItem at \fIviewPos.\fR Note that \fIviewPos\fR is in the coordinate system of viewport(), not in the listview's own, much larger, coordinate system..PPitemAt() returns 0 if there is no such item..PPNote, that you also get the pointer to the item if \fIviewPos\fR points onto the root decoration (see setRootIsDecorated()) of the item. To check if \fIviewPos\fR is on the root decoration of the item or not, you can do something like.PP.nf.br QListViewItem *i = itemAt( p );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -