📄 qlistview.3qt
字号:
.br.ti -1c.BI "void \fBspacePressed\fR ( QListViewItem * )".br.ti -1c.BI "void \fBrightButtonClicked\fR ( QListViewItem *, const QPoint &, int )".br.ti -1c.BI "void \fBrightButtonPressed\fR ( QListViewItem *, const QPoint &, int )".br.ti -1c.BI "void \fBmouseButtonPressed\fR ( int button, QListViewItem * item, const QPoint & pos, int c )".br.ti -1c.BI "void \fBmouseButtonClicked\fR ( int button, QListViewItem * item, const QPoint & pos, int c )".br.ti -1c.BI "void \fBcontextMenuRequested\fR ( QListViewItem * item, const QPoint & pos, int col )".br.ti -1c.BI "void \fBonItem\fR ( QListViewItem * i )".br.ti -1c.BI "void \fBonViewport\fR ()".br.ti -1c.BI "void \fBexpanded\fR ( QListViewItem * item )".br.ti -1c.BI "void \fBcollapsed\fR ( QListViewItem * item )".br.ti -1c.BI "void \fBdropped\fR ( QDropEvent * e )".br.ti -1c.BI "void \fBitemRenamed\fR ( QListViewItem * item, int col, const QString & text )".br.ti -1c.BI "void \fBitemRenamed\fR ( QListViewItem * item, int col )".br.in -1c.SS "Properties".in +1c.ti -1c.BI "bool \fBallColumnsShowFocus\fR - whether items should show keyboard focus using all columns".br.ti -1c.BI "int \fBchildCount\fR - the number of parentless (top-level) QListViewItem objects in this QListView \fI(read " "only" ")\fR".br.ti -1c.BI "int \fBcolumns\fR - the number of columns in this list view \fI(read " "only" ")\fR".br.ti -1c.BI "RenameAction \fBdefaultRenameAction\fR - what action to perform when the editor loses focus during renaming".br.ti -1c.BI "int \fBitemMargin\fR - the advisory item margin that list items may use".br.ti -1c.BI "bool multiSelection - whether the list view is in multi-selection or extended-selection mode \fI(obsolete)\fR".br.ti -1c.BI "ResizeMode \fBresizeMode\fR - whether " "all" ", none or the only the last column should be resized".br.ti -1c.BI "bool \fBrootIsDecorated\fR - whether the list view shows open/close signs on root items".br.ti -1c.BI "SelectionMode \fBselectionMode\fR - the list view's selection mode".br.ti -1c.BI "bool \fBshowSortIndicator\fR - whether the list view header should display a sort indicator".br.ti -1c.BI "bool \fBshowToolTips\fR - whether this list view should show tooltips for truncated column texts".br.ti -1c.BI "int \fBtreeStepSize\fR - the number of pixels a child is offset from its parent".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBcontentsMousePressEvent\fR ( QMouseEvent * e )".br.ti -1c.BI "virtual void \fBcontentsMouseReleaseEvent\fR ( QMouseEvent * e )".br.ti -1c.BI "virtual void \fBcontentsMouseMoveEvent\fR ( QMouseEvent * e )".br.ti -1c.BI "virtual void \fBcontentsMouseDoubleClickEvent\fR ( QMouseEvent * e )".br.ti -1c.BI "virtual QDragObject * \fBdragObject\fR ()".br.ti -1c.BI "virtual void \fBstartDrag\fR ()".br.ti -1c.BI "virtual void \fBresizeEvent\fR ( QResizeEvent * e )".br.ti -1c.BI "virtual void \fBdrawContentsOffset\fR ( QPainter * p, int ox, int oy, int cx, int cy, int cw, int ch )".br.ti -1c.BI "virtual void \fBpaintEmptyArea\fR ( QPainter * p, const QRect & rect )".br.in -1c.SS "Protected Slots".in +1c.ti -1c.BI "void \fBupdateContents\fR ()".br.ti -1c.BI "void \fBdoAutoScroll\fR ()".br.in -1c.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. The user may select one or many items (depending on the SelectionMode) and sort the list in increasing or decreasing order by any column..PPThe simplest pattern of use is to create a QListView, add some column headers using addColumn() and create one or more QListViewItem or QCheckListItem objects with the QListView as parent:.PP.nf.br QListView * table;.fi.PP.nf.br table->addColumn( "Qualified name" );.br table->addColumn( "Namespace" );.fi.PP.nf.br element = new QListViewItem( table, qName, namespaceURI );.fi.PPFurther nodes can be added to the list view object (the root of the tree) or as child nodes to QListViewItems:.PP.nf.br for ( int i = 0 ; i < attributes.length(); i++ ) {.br new QListViewItem( element, attributes.qName(i), attributes.uri(i) );.br }.fi.PP(From xml/tagreader-with-features/structureparser.cpp).PPThe main setup functions are: <center>.nf.TSl - l. Function Action addColumn() Adds a column with a text label and perhaps width. Columns are counted from the left starting with column 0. setColumnWidthMode() Sets the column to be resized automatically or not. setAllColumnsShowFocus() Sets whether items should show keyboard focus using all columns or just column 0. The default is to show focus just using column 0. setRootIsDecorated() Sets whether root items should show open/close decoration to their left. The default is FALSE. setTreeStepSize() Sets how many pixels an item's children are indented relative to their parent. The default is 20. This is mostly a matter of taste. setSorting().TE.fi</center>.PPTo handle events such as mouse presses on the list view, 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 (whether it is on-screen or not). firstChild() returns the list view's first item (not necessarily visible on-screen)..PPYou can iterate over visible items using QListViewItem::itemBelow(); over a list view's top-level items using QListViewItem::firstChild() and QListViewItem::nextSibling(); or every item using a QListViewItemIterator. See the QListViewItem documentation for examples of traversal..PPAn item can be moved amongst its siblings using QListViewItem::moveItem(). To move an item in the hierarchy use takeItem() and insertItem(). Item's (and all their child items) are deleted with \fCdelete\fR; to delete all the list view's items use clear()..PPThere are a variety of selection modes described in the QListView::SelectionMode documentation. The default is Single selection, which you can change using setSelectionMode()..PPBecause QListView offers multiple selection it must display keyboard focus and selection state separately. Therefore there are functions both to set the selection state of an item (setSelected()) and to set which item displays keyboard focus (setCurrentItem())..PPQListView emits two groups of signals; one group signals changes in selection/focus state and one indicates selection. The first group consists of selectionChanged() (applicable to all list views), selectionChanged(QListViewItem*) (applicable only to a Single selection list view), and currentChanged(QListViewItem*). The second group consists of doubleClicked(QListViewItem*), returnPressed(QListViewItem*), rightButtonClicked(QListViewItem*, const QPoint&, int), etc..PPNote that changing the state of the list view in a slot connected to a list view signal may cause unexpected side effects. If you need to change the list view's state in response to a signal, use a single shot timer with a time out of 0, and connect this timer to a slot that modifies the list view's state..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..PPIf selectionMode() is Single (the default) the user can select one item at a time, e.g. by clicking an item with the mouse, see QListView::SelectionMode for details..PPThe list view can be navigated either using the mouse or the keyboard. Clicking a \fB-\fR icon closes an item (hides its children) and clicking a \fB+\fR icon opens an item (shows its children). The keyboard controls are these: <center>.nf.TSl - l. Keypress Action Home Make the first item current and visible. End Make the last item current and visible. Page Up Make the item above the top visible item current and visible. Page Down Make the item below the bottom visible item current and visible. Up Arrow Make the item above the current item current and visible. Down Arrow Make the item below the current item current and visible. Left Arrow If the current item is closed ( Right Arrow If the current item is closed (.TE.fi</center>.PPIf the user starts typing letters with the focus in the list view an incremental search will occur. For example if the user types 'd' the current item will change to the first item that begins with the letter 'd'; if they then type 'a', the current item will change to the first item that begins with 'da', and so on. If no item begins with the letters they type the current item doesn't change..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]".PPSee also QListViewItem, QCheckListItem, and Advanced Widgets..SS "Member Type Documentation".SH "QListView::RenameAction"This enum describes whether a rename operation is accepted if the rename editor loses focus without the user pressing Enter..TP\fCQListView::Accept\fR - Rename if Enter is pressed or focus is lost..TP\fCQListView::Reject\fR - Discard the rename operation if focus is lost (and Enter has not been pressed)..SH "QListView::ResizeMode"This enum describes how the list view's header adjusts to resize events which affect the width of the list view..TP\fCQListView::NoColumn\fR - The columns do not get resized in resize events..TP\fCQListView::AllColumns\fR - All columns are resized equally to fit the width of the list view..TP\fCQListView::LastColumn\fR - The last column is resized to fit the width of the list view..SH "QListView::SelectionMode"This enumerated type is used by QListView to indicate how it reacts to selection by the user..TP\fCQListView::Single\fR - When the user selects an item, any already-selected item becomes unselected. The user can unselect the selected item by clicking on some empty space within the view..TP\fCQListView::Multi\fR - When the user selects an item in the usual way, 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 stays pressed..TP\fCQListView::Extended\fR - When the user selects an item in the usual 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 over them..TP\fCQListView::NoSelection\fR - Items cannot be selected..PPIn other words, Single is a real single-selection list view, Multi a real multi-selection list view, Extended is a list view where users can select multiple items but usually want to select either just one or a range of contiguous items, and NoSelection is a list view 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..TP\fCQListView::Manual\fR - the column width does not change automatically..TP\fCQListView::Maximum\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 that the column is always resized to the width of the item with the largest width in the column..PPSee also setColumnWidth(), setColumnWidthMode(), and columnWidth()..SH MEMBER FUNCTION DOCUMENTATION.SH "QListView::QListView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )"Constructs a new empty list view called \fIname\fR with parent \fIparent\fR..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 WStaticContents and WNoAutoErase should be cleared..PPSee also QWidget::clearWFlags() and Qt::WidgetFlags..SH "QListView::~QListView ()"Destroys the list view, deleting all its items, and frees up all allocated resources..SH "int QListView::addColumn ( const QString & label, int width = -1 )\fC [virtual]\fR"Adds a \fIwidth\fR pixels wide column with the column header \fIlabel\fR to the list view, and returns the index of the new column..PPAll columns apart from the first one are inserted to the right of the existing ones..PPIf \fIwidth\fR is negative, the new column's WidthMode is set to Maximum instead of Manual..PPSee also setColumnText(), setColumnWidth(), and setColumnWidthMode()..PPExamples:.)l addressbook/centralwidget.cpp, checklists/checklists.cpp, dirview/main.cpp, fileiconview/mainwindow.cpp, listviews/listviews.cpp, and qdir/qdir.cpp..SH "int QListView::addColumn ( const QIconSet & iconset, const QString & label, int width = -1 )\fC [virtual]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAdds a \fIwidth\fR pixels wide new column with the header \fIlabel\fR and the \fIiconset\fR to the list view, and returns the index of the column..PPIf \fIwidth\fR is negative, the new column's WidthMode is set to Maximum, and to Manual otherwise..PPSee also setColumnText(), setColumnWidth(), and setColumnWidthMode()..SH "void QListView::adjustColumn ( int col )\fC [slot]\fR"Adjusts the column \fIcol\fR to its preferred width.SH "bool QListView::allColumnsShowFocus () const"Returns TRUE if items should show keyboard focus using all columns; otherwise returns FALSE. See the "allColumnsShowFocus" property for details..SH "int QListView::childCount () const"Returns the number of parentless (top-level) QListViewItem objects in this QListView. See the "childCount" property for details..SH "void QListView::clear ()\fC [virtual slot]\fR"Removes and deletes all the items in this list view and triggers an update..PPSee also triggerUpdate()..PPExamples:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -