📄 qiconview.3qt
字号:
.ti -1c.BI "void \fBmouseButtonPressed\fR ( int button, QIconViewItem * item, const QPoint & pos )".br.ti -1c.BI "void \fBmouseButtonClicked\fR ( int button, QIconViewItem * item, const QPoint & pos )".br.ti -1c.BI "void \fBcontextMenuRequested\fR ( QIconViewItem * item, const QPoint & pos )".br.ti -1c.BI "void \fBdropped\fR ( QDropEvent * e, const QValueList<QIconDragItem> & lst )".br.ti -1c.BI "void \fBmoved\fR ()".br.ti -1c.BI "void \fBonItem\fR ( QIconViewItem * item )".br.ti -1c.BI "void \fBonViewport\fR ()".br.ti -1c.BI "void \fBitemRenamed\fR ( QIconViewItem * item, const QString & name )".br.ti -1c.BI "void \fBitemRenamed\fR ( QIconViewItem * item )".br.in -1c.SS "Properties".in +1c.ti -1c.BI "Arrangement \fBarrangement\fR - the arrangement mode of the icon view".br.ti -1c.BI "bool \fBautoArrange\fR - whether the icon view rearranges its items when a new item is inserted".br.ti -1c.BI "uint \fBcount\fR - the number of items in the icon view \fI(read " "only" ")\fR".br.ti -1c.BI "int \fBgridX\fR - the horizontal grid of the icon view".br.ti -1c.BI "int \fBgridY\fR - the vertical grid of the icon view".br.ti -1c.BI "QBrush \fBitemTextBackground\fR - the brush that should be used when drawing the background of an item's text".br.ti -1c.BI "ItemTextPos \fBitemTextPos\fR - the position where the text of each item is drawn".br.ti -1c.BI "bool \fBitemsMovable\fR - whether the user is allowed to move items around in the icon view".br.ti -1c.BI "int \fBmaxItemTextLength\fR - the maximum length (in " "characters" ") that an item's text may have".br.ti -1c.BI "int \fBmaxItemWidth\fR - the maximum width that an item may have".br.ti -1c.BI "ResizeMode \fBresizeMode\fR - the resize mode of the icon view".br.ti -1c.BI "SelectionMode \fBselectionMode\fR - the selection mode of the icon view".br.ti -1c.BI "bool \fBshowToolTips\fR - whether the icon view will display a tool tip with the complete text for any truncated item text".br.ti -1c.BI "bool \fBsortDirection\fR - whether the sort direction for inserting new items is ascending; \fI(read " "only" ")\fR".br.ti -1c.BI "bool \fBsorting\fR - whether the icon view sorts on insertion \fI(read " "only" ")\fR".br.ti -1c.BI "int \fBspacing\fR - the space in pixels between icon view items".br.ti -1c.BI "bool \fBwordWrapIconText\fR - whether the item text will be word-wrapped if it is too long".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBdrawRubber\fR ( QPainter * p )".br.ti -1c.BI "virtual QDragObject * \fBdragObject\fR ()".br.ti -1c.BI "virtual void \fBstartDrag\fR ()".br.ti -1c.BI "virtual void \fBinsertInGrid\fR ( QIconViewItem * item )".br.ti -1c.BI "virtual void \fBdrawBackground\fR ( QPainter * p, const QRect & r )".br.ti -1c.BI "void \fBemitSelectionChanged\fR ( QIconViewItem * i = 0 )".br.ti -1c.BI "QIconViewItem * \fBmakeRowLayout\fR ( QIconViewItem * begin, int & y, bool & changed )".br.in -1c.SS "Protected Slots".in +1c.ti -1c.BI "virtual void \fBdoAutoScroll\fR ()".br.ti -1c.BI "virtual void \fBadjustItems\fR ()".br.ti -1c.BI "virtual void \fBslotUpdate\fR ()".br.in -1c.SH DESCRIPTIONThe QIconView class provides an area with movable labelled icons..PPThe QIconView can display and manage a grid or other 2D layout of labelled icons. Each labelled icon is a QIconViewItem. Items (QIconViewItems) can be added or deleted at any time; items can be moved within the QIconView. Single or multiple items can be selected. Items can be renamed in-place. QIconView also supports drag and drop..PPEach item contains a label string, a pixmap or picture (the icon itself) and optionally an index key. The index key is used for sorting the items and defaults to the label string. The label string can be displayed below or to the right of the icon (see ItemTextPos)..PPThe simplest way to create a QIconView is to create a QIconView object and create some QIconViewItems with the QIconView as their parent, set the icon view's geometry and show it. Below is an example of how such code might look:.PP.nf.br QIconView *iv = new QIconView( this );.br QDir dir( path, "*.xpm" );.br for ( uint i = 0; i < dir.count(); i++ ) {.br (void) new QIconViewItem( iv, dir[i], QPixmap( path + dir[i] ) );.br }.br iv->resize( 600, 400 );.br iv->show();.br.fi.PPThe QIconViewItem call passes a pointer to the QIconView we wish to populate followed by the label text and a QPixmap..PPWhen an item is inserted the QIconView allocates a position for it. The default arrangement is LeftToRight -- QIconView fills up the \fIleft-most\fR column from top to bottom, then moves one column \fIright\fR and fills that from top to bottom and so on. The arrangement can be modified with any of the following approaches:.TPCall setArrangement(), e.g. with TopToBottom which will fill the \fItop-most\fR row from left to right, then moves one row \fIdown\fR and fills that row from left to right and so on..TPConstruct each QIconViewItem using a constructor which allows you to specify which item the new one is to follow..TPCall setSorting() or sort() to sort the items..PPItems which are \fIselectable\fR may be selected depending on the SelectionMode (default is Single). Because QIconView offers multiple selection it has to display keyboard focus and selection state separately. Therefore there are functions to set the selection state of an item (setSelected()) and to select which item displays keyboard focus (setCurrentItem()). When multiple items may be selected the icon view provides a rubberband, too..PPWhen in-place renaming is enabled (it is disabled by default), the user may change the item's label. They do this by selecting the item (single clicking it or navigating to it with the arrow keys), then single clicking it (or pressing F2), and entering their text. If no key has been set with QIconViewItem::setKey() the new text will also serve as the key. (See QIconViewItem::setRenameEnabled().).PPQIconView offers functions similar to QListView and QListBox, such as takeItem(), clearSelection(), setSelected(), setCurrentItem(), currentItem() and many more..PPBecause the internal structure used to store the icon view items is linear (a double-linked list), no iterator class is needed to iterate over all the items. Instead we iterate by getting the first item from the \fIicon view\fR and then each subsequent (QIconViewItem::nextItem()) from each \fIitem\fR in turn:.PP.nf.br for ( QIconViewItem *item = iv->firstItem(); item; item = item->nextItem() ).br do_something( item );.br.fi.PPQIconView supports the drag and drop of items within the QIconView itself. It also supports the drag and drop of items out of or into the QIconView and drag and drop onto items themselves. The drag and drop of items outside the QIconView can be achieved in a simple way with basic functionality, or in a more sophisticated way which provides more power and control..PPThe simple approach to dragging items out of the icon view is to subclass QIconView and reimplement QIconView::dragObject()..PP.nf.br QDragObject *MyIconView::dragObject().br {.br return new QTextDrag( currentItem()->text(), this );.br }.br.fi.PPIn this example we create a QTextDrag object, (derived from QDragObject), containing the item's label and return it as the drag object. We could just as easily have created a QImageDrag from the item's pixmap and returned that instead..PPQIconViews and their QIconViewItems can also be the targets of drag and drops. To make the QIconView itself able to accept drops connect to the dropped() signal. When a drop occurs this signal will be emitted with a QDragEvent and a QValueList of QIconDragItems. To make a QIconViewItem into a drop target subclass QIconViewItem and reimplement QIconViewItem::acceptDrop() and QIconViewItem::dropped()..PP.nf.br bool MyIconViewItem::acceptDrop( const QMimeSource *mime ) const.br {.br if ( mime->provides( "text/plain" ) ).br return TRUE;.br return FALSE;.br }.br.br void MyIconViewItem::dropped( QDropEvent *evt, const QValueList<QIconDragItem>& ).br {.br QString label;.br if ( QTextDrag::decode( evt, label ) ).br setText( label );.br }.br.fi.PPSee iconview/simple_dd/main.h and iconview/simple_dd/main.cpp for a simple drag and drop example which demonstrates drag and drop between a QIconView and a QListBox..PPIf you want to use extended drag-and-drop or have drag shapes drawn you have to take a more sophisticated approach..PPThe first part is starting drags -- you should use a QIconDrag (or a class derived from it) for the drag object. In dragObject() create the drag object, populate it with QIconDragItems and return it. Normally such a drag should offer each selected item's data. So in dragObject() you should iterate over all the items, and create a QIconDragItem for each selected item, and append these items with QIconDrag::append() to the QIconDrag object. You can use QIconDragItem::setData() to set the data of each item that should be dragged. If you want to offer the data in additional mime-types, it's best to use a class derived from QIconDrag, which implements additional encoding and decoding functions..PPWhen a drag enters the icon view, there is little to do. Simply connect to the dropped() signal and reimplement QIconViewItem::acceptDrop() and QIconViewItem::dropped(). If you've used a QIconDrag (or a subclass of it) the second argument to the dropped signal contains a QValueList of QIconDragItems -- you can access their data by calling QIconDragItem::data..PPFor an example implementation of complex drag-and-drop look at the qfileiconview example (qt/examples/qfileiconview)..PPSee also QIconViewItem::setDragEnabled(), QIconViewItem::setDropEnabled(), QIconViewItem::acceptDrop(), QIconViewItem::dropped() and Advanced Widgets..PP.ce 1.B "[Image Omitted]".PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -