The Q3IconView class provides an area with movable labelled icons. 更多...
| 头: | #include <Q3IconView> |
| 继承: | Q3ScrollView |
| enum | Arrangement { LeftToRight, TopToBottom } |
| typedef | ComparisonFlags |
| enum | ItemTextPos { Bottom, Right } |
| enum | ResizeMode { Fixed, Adjust } |
| enum | SelectionMode { Single, Multi, Extended, NoSelection } |
| enum | StringComparisonMode { CaseSensitive, ExactMatch, BeginsWith, EndsWith, Contains } |
|
|
| Q3IconView (QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0) | |
| virtual | ~Q3IconView () |
| Arrangement | arrangement () const |
| bool | autoArrange () const |
| virtual void | clear () |
| virtual void | clearSelection () |
| uint | count () const |
| Q3IconViewItem * | currentItem () const |
| void | ensureItemVisible (Q3IconViewItem * item ) |
| Q3IconViewItem * | findFirstVisibleItem (const QRect & r ) const |
| Q3IconViewItem * | findItem (const QPoint & pos ) const |
| Q3IconViewItem * | findItem (const QString & text , ComparisonFlags compare = BeginsWith | Qt::CaseSensitive) const |
| Q3IconViewItem * | findLastVisibleItem (const QRect & r ) const |
| Q3IconViewItem * | firstItem () const |
| int | gridX () const |
| int | gridY () const |
| int | index (const Q3IconViewItem * item ) const |
| virtual void | insertItem (Q3IconViewItem * item , Q3IconViewItem * after = 0L) |
| virtual void | invertSelection () |
| bool | isRenaming () const |
| QBrush | itemTextBackground () const |
| ItemTextPos | itemTextPos () const |
| bool | itemsMovable () const |
| Q3IconViewItem * | lastItem () const |
| int | maxItemTextLength () const |
| int | maxItemWidth () const |
| virtual void | repaintItem (Q3IconViewItem * item ) |
| void | repaintSelectedItems () |
| ResizeMode | resizeMode () const |
| virtual void | selectAll (bool select ) |
| SelectionMode | selectionMode () const |
| virtual void | setArrangement (Arrangement am ) |
| virtual void | setAutoArrange (bool b ) |
| virtual void | setCurrentItem (Q3IconViewItem * item ) |
| virtual void | setGridX (int rx ) |
| virtual void | setGridY (int ry ) |
| virtual void | setItemTextBackground (const QBrush & b ) |
| virtual void | setItemTextPos (ItemTextPos pos ) |
| virtual void | setItemsMovable (bool b ) |
| virtual void | setMaxItemTextLength (int w ) |
| virtual void | setMaxItemWidth (int w ) |
| virtual void | setResizeMode (ResizeMode am ) |
| virtual void | setSelected (Q3IconViewItem * item , bool s , bool cb = false) |
| virtual void | setSelectionMode (SelectionMode m ) |
| virtual void | setShowToolTips (bool b ) |
| void | setSorting (bool sort , bool ascending = true) |
| virtual void | setSpacing (int sp ) |
| virtual void | setWordWrapIconText (bool b ) |
| bool | showToolTips () const |
| virtual void | sort (bool ascending = true) |
| bool | sortDirection () const |
| bool | sorting () const |
| int | spacing () const |
| virtual void | takeItem (Q3IconViewItem * item ) |
| bool | wordWrapIconText () const |
| virtual bool | eventFilter (QObject * o , QEvent * e ) |
| virtual QVariant | inputMethodQuery (Qt::InputMethodQuery query ) const |
| virtual QSize | minimumSizeHint () const |
| virtual void | showEvent (QShowEvent *) |
| virtual QSize | sizeHint () const |
| virtual void | arrangeItemsInGrid (const QSize & grid , bool update = true) |
| virtual void | arrangeItemsInGrid (bool update = true) |
| virtual void | setContentsPos (int x , int y ) |
| void | clicked (Q3IconViewItem * item ) |
| void | clicked (Q3IconViewItem * item , const QPoint & pos ) |
| void | contextMenuRequested (Q3IconViewItem * item , const QPoint & pos ) |
| void | currentChanged (Q3IconViewItem * item ) |
| void | doubleClicked (Q3IconViewItem * item ) |
| void | dropped (QDropEvent * e , const Q3ValueList<Q3IconDragItem> & lst ) |
| void | itemRenamed (Q3IconViewItem * item , const QString & name ) |
| void | itemRenamed (Q3IconViewItem * item ) |
| void | mouseButtonClicked (int button , Q3IconViewItem * item , const QPoint & pos ) |
| void | mouseButtonPressed (int button , Q3IconViewItem * item , const QPoint & pos ) |
| void | moved () |
| void | onItem (Q3IconViewItem * item ) |
| void | onViewport () |
| void | pressed (Q3IconViewItem * item ) |
| void | pressed (Q3IconViewItem * item , const QPoint & pos ) |
| void | returnPressed (Q3IconViewItem * item ) |
| void | rightButtonClicked (Q3IconViewItem * item , const QPoint & pos ) |
| void | rightButtonPressed (Q3IconViewItem * item , const QPoint & pos ) |
| void | selectionChanged () |
| void | selectionChanged (Q3IconViewItem * item ) |
| virtual Q3DragObject * | dragObject () |
| virtual void | drawBackground (QPainter * p , const QRect & r ) |
| virtual void | drawRubber (QPainter * p ) |
| void | emitSelectionChanged (Q3IconViewItem * i = 0) |
| virtual void | insertInGrid (Q3IconViewItem * item ) |
| Q3IconViewItem * | makeRowLayout (Q3IconViewItem * begin , int & y , bool & changed ) |
| virtual void | startDrag () |
| virtual void | changeEvent (QEvent * ev ) |
| virtual void | contentsContextMenuEvent (QContextMenuEvent * e ) |
| virtual void | contentsDragEnterEvent (QDragEnterEvent * e ) |
| virtual void | contentsDragLeaveEvent (QDragLeaveEvent * e ) |
| virtual void | contentsDragMoveEvent (QDragMoveEvent * e ) |
| virtual void | contentsDropEvent (QDropEvent * e ) |
| virtual void | contentsMouseDoubleClickEvent (QMouseEvent * e ) |
| virtual void | contentsMouseMoveEvent (QMouseEvent * e ) |
| virtual void | contentsMousePressEvent (QMouseEvent * e ) |
| virtual void | contentsMouseReleaseEvent (QMouseEvent * e ) |
| virtual void | drawContents (QPainter * p , int cx , int cy , int cw , int ch ) |
| virtual void | enterEvent (QEvent * e ) |
| virtual void | focusInEvent (QFocusEvent * e ) |
| virtual void | focusOutEvent (QFocusEvent * e ) |
| virtual void | keyPressEvent (QKeyEvent * e ) |
| virtual void | resizeEvent (QResizeEvent * e ) |
| virtual void | adjustItems () |
| virtual void | doAutoScroll () |
| virtual void | slotUpdate () |
The Q3IconView class provides an area with movable labelled icons.
A Q3IconView can display and manage a grid or other 2D layout of labelled icons. Each labelled icon is a Q3IconViewItem . Items (Q3IconViewItems) can be added or deleted at any time; items can be moved within the Q3IconView . Single or multiple items can be selected. Items can be renamed in-place. Q3IconView also supports 拖放 .
Each item contains a label string, a pixmap or picture (the icon itself) and optionally a sort key. The sort 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 ).
The simplest way to create a Q3IconView is to create a Q3IconView object and create some Q3IconViewItems with the Q3IconView as their parent, set the icon view's geometry and show it. For example:
Q3IconView *iv = new Q3IconView(this); QDir dir(path, "*.xpm"); for (uint i = 0; i < dir.count(); i++) { (void) new Q3IconViewItem(iv, dir[i], QPixmap(path + dir[i])); } iv->resize(600, 400); iv->show();
The Q3IconViewItem call passes a pointer to the Q3IconView we wish to populate, along with the label text and a QPixmap .
When an item is inserted the Q3IconView allocates a position for it. Existing items are rearranged if autoArrange () is true. The default arrangement is LeftToRight -- the Q3IconView fills up the left-most column from top to bottom, then moves one column right and fills that from top to bottom and so on. The arrangement can be modified with any of the following approaches:
The spacing between items is set with setSpacing (). Items can be laid out using a fixed grid using setGridX () 和 setGridY (); by default the Q3IconView calculates a grid dynamically. The position of items' label text is set with setItemTextPos (). The text's background can be set with setItemTextBackground (). The maximum width of an item and of its text are set with setMaxItemWidth () 和 setMaxItemTextLength (). The label text will be word-wrapped if it is too long; this is controlled by setWordWrapIconText (). If the label text is truncated, the user can still see the entire text in a tool tip if they hover the mouse over the item. This is controlled with setShowToolTips ().
Items which are selectable may be selected depending on the SelectionMode ; the default is Single . Because Q3IconView offers multiple selection it must 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.
When 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 Q3IconViewItem::setKey () the new text will also serve as the key. (See Q3IconViewItem::setRenameEnabled ().)
You can control whether users can move items themselves with setItemsMovable ().
Because the internal structure used to store the icon view items is linear, no iterator class is needed to iterate over all the items. Instead we iterate by getting the first item from the 图标视图 and then each subsequent ( Q3IconViewItem::nextItem ()) from each item in turn:
for (Q3IconViewItem *item = iv->firstItem(); item; item = item->nextItem()) do_something(item);
Q3IconView
还提供
currentItem
(). You can search for an item using
findItem
() (searching by position or for label text) and with
findFirstVisibleItem
() 和
findLastVisibleItem
(). The number of items is returned by
count
(). An item can be removed from an icon view using
takeItem
(); to delete an item use
delete
. All the items can be deleted with
clear
().
The Q3IconView emits a wide range of useful signals, including selectionChanged (), currentChanged (), clicked (), moved () 和 itemRenamed ().
Q3IconView supports the drag and drop of items within the Q3IconView itself. It also supports the drag and drop of items out of or into the Q3IconView and drag and drop onto items themselves. The drag and drop of items outside the Q3IconView can be achieved in a simple way with basic functionality, or in a more sophisticated way which provides more power and control.
The simple approach to dragging items out of the icon view is to subclass Q3IconView 并重实现 Q3IconView::dragObject ().
Q3DragObject *MyIconView::dragObject() { return new Q3TextDrag(currentItem()->text(), this); }
In this example we create a Q3TextDrag object, (derived from Q3DragObject ), containing the item's label and return it as the drag object. We could just as easily have created a Q3ImageDrag from the item's pixmap and returned that instead.
Q3IconViews and their Q3IconViewItems can also be the targets of drag and drops. To make the Q3IconView itself able to accept drops connect to the dropped () signal. When a drop occurs this signal will be emitted with a QDragEvent and a QLinkedList of Q3IconDragItems. To make a Q3IconViewItem into a drop target subclass Q3IconViewItem 并重实现 Q3IconViewItem::acceptDrop () 和 Q3IconViewItem::dropped ().
bool MyIconViewItem::acceptDrop(const QMimeSource *mime) const { if (mime->provides("text/plain")) return true; return false; } void MyIconViewItem::dropped(QDropEvent *evt, const Q3ValueList<Q3IconDragItem>&) { QString label; if (Q3TextDrag::decode(evt, label)) setText(label); }
If you want to use extended drag-and-drop or have drag shapes drawn you must take a more sophisticated approach.
The first part is starting drags -- you should use a Q3IconDrag (or a class derived from it) for the drag object. In dragObject () create the drag object, populate it with Q3IconDragItems 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 Q3IconDragItem for each selected item, and append these items with Q3IconDrag::append () to the Q3IconDrag object. You can use Q3IconDragItem::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 Q3IconDrag , which implements additional encoding and decoding functions.
When a drag enters the icon view, there is little to do. Simply connect to the dropped () signal and reimplement Q3IconViewItem::acceptDrop () 和 Q3IconViewItem::dropped (). If you've used a Q3IconDrag (or a subclass of it) the second argument to the dropped signal contains a QLinkedList of Q3IconDragItems -- you can access their data by calling Q3IconDragItem::data () on each one.
For an example implementation of complex drag-and-drop look at the fileiconview example (qt/examples/fileiconview).
另请参阅 Q3IconViewItem::setDragEnabled (), Q3IconViewItem::setDropEnabled (), Q3IconViewItem::acceptDrop (),和 Q3IconViewItem::dropped ().
This enum type determines in which direction the items flow when the view runs out of space.
| 常量 | 值 | 描述 |
|---|---|---|
Q3IconView::LeftToRight
|
0
|
Items which don't fit into the view go further down (you get a vertical scroll bar) |
Q3IconView::TopToBottom
|
1
|
Items which don't fit into the view go further right (you get a horizontal scroll bar) |
This typedef is used in Q3IconView 's API for values that are OR'd combinations of StringComparisonMode 值。
另请参阅 StringComparisonMode .
This enum type specifies the position of the item text in relation to the icon.
| 常量 | 值 | 描述 |
|---|---|---|
Q3IconView::Bottom
|
0
|
The text is drawn below the icon. |
Q3IconView::Right
|
1
|
The text is drawn to the right of the icon. |
This enum type is used to tell Q3IconView how it should treat the positions of its icons when the widget is resized. The modes are:
| 常量 | 值 | 描述 |
|---|---|---|
Q3IconView::Fixed
|
0
|
The icons' positions are not changed. |
Q3IconView::Adjust
|
1
|
The icons' positions are adjusted to be within the new geometry, if possible. |
This enumerated type is used by Q3IconView to indicate how it reacts to selection by the user. It has four values:
| 常量 | 值 | 描述 |
|---|---|---|
Q3IconView::Single
|
0
|
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. (The application programmer can, using Q3IconView::clearSelection ().) |
Q3IconView::Multi
|
1
|
When the user selects an item, e.g. by navigating to it with the keyboard arrow keys or by clicking it, the selection status of that item is toggled and the other items are left alone. |
Q3IconView::Extended
|
2
|
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. 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 stays pressed. |
Q3IconView::NoSelection
|
3
|
无法选择项。 |
To summarize:
Single
is a real single-selection icon view;
Multi
a real multi-selection icon view;
Extended
is an icon view in which users can select multiple items but usually want to select either just one or a range of contiguous items; and
NoSelection
mode is for an icon view where the user can look but not touch.
This enum type is used to set the string comparison mode when searching for an item. We'll refer to the string being searched as the 'target' string.
| 常量 | 值 | 描述 |
|---|---|---|
Q3IconView::CaseSensitive
|
0x00001
|
The strings must match case sensitively. |
Q3IconView::ExactMatch
|
0x00010
|
The target and search strings must match exactly. |
Q3IconView::BeginsWith
|
0x00002
|
The target string begins with the search string. |
Q3IconView::EndsWith
|
0x00004
|
The target string ends with the search string. |
Q3IconView::Contains
|
0x00008
|
The target string contains the search string. |
If you OR these flags together (excluding
CaseSensitive
), the search criteria be applied in the following order:
ExactMatch
,
BeginsWith
,
EndsWith
,
Contains
.
Matching is case-insensitive unless
CaseSensitive
有设置。
CaseSensitive
can be OR-ed with any combination of the other flags.
另请参阅 ComparisonFlags .
This property holds the arrangement mode of the icon view.
This can be LeftToRight or TopToBottom 。默认为 LeftToRight .
访问函数:
| Arrangement | arrangement () const |
| virtual void | setArrangement (Arrangement am ) |
This property holds whether the icon view rearranges its items when a new item is inserted.
默认为 true。
Note that if the icon view is not visible at the time of insertion, Q3IconView defers all position-related work until it is shown and then calls arrangeItemsInGrid ().
访问函数:
| bool | autoArrange () const |
| virtual void | setAutoArrange (bool b ) |
This property holds the number of items in the icon view.
访问函数:
| uint | count () const |
This property holds the horizontal grid of the icon view.
If the value is -1, (the default), Q3IconView computes suitable column widths based on the icon view's contents.
Note that setting a grid width overrides setMaxItemWidth ().
访问函数:
| int | gridX () const |
| virtual void | setGridX (int rx ) |
This property holds the vertical grid of the icon view.
If the value is -1, (the default), Q3IconView computes suitable column heights based on the icon view's contents.
访问函数:
| int | gridY () const |
| virtual void | setGridY (int ry ) |
This property holds the brush to use when drawing the background of an item's text.
By default this brush is set to Qt::NoBrush , meaning that only the normal icon view background is used.
访问函数:
| QBrush | itemTextBackground () const |
| virtual void | setItemTextBackground (const QBrush & b ) |
This property holds the position where the text of each item is drawn.
Valid values are Bottom or Right 。默认为 Bottom .
访问函数:
| ItemTextPos | itemTextPos () const |
| virtual void | setItemTextPos (ItemTextPos pos ) |
This property holds whether the user is allowed to move items around in the icon view.
默认为 true。
访问函数:
| bool | itemsMovable () const |
| virtual void | setItemsMovable (bool b ) |
This property holds the maximum length (in characters) that an item's text may have.
The default is 255 characters.
访问函数:
| int | maxItemTextLength () const |
| virtual void | setMaxItemTextLength (int w ) |
This property holds the maximum width that an item may have.
The default is 100 pixels.
Note that if the gridX () value is set Q3IconView will ignore this property.
访问函数:
| int | maxItemWidth () const |
| virtual void | setMaxItemWidth (int w ) |
This property holds the resize mode of the icon view.
This can be Fixed or Adjust 。默认为 Fixed 。见 ResizeMode .
访问函数:
| ResizeMode | resizeMode () const |
| virtual void | setResizeMode (ResizeMode am ) |
This property holds the selection mode of the icon view.
This can be Single (默认), Extended , Multi or NoSelection .
访问函数:
| SelectionMode | selectionMode () const |
| virtual void | setSelectionMode (SelectionMode m ) |
This property holds whether the icon view will display a tool tip with the complete text for any truncated item text.
The default is true. Note that this has no effect if setWordWrapIconText () is true, as it is by default.
访问函数:
| bool | showToolTips () const |
| virtual void | setShowToolTips (bool b ) |
This property holds whether the sort direction for inserting new items is ascending;.
The default is true (i.e. ascending). This sort direction is only meaningful if both sorting () 和 autoArrange () are true.
To set the sort direction, use setSorting ()
访问函数:
| bool | sortDirection () const |
This property holds whether the icon view sorts on insertion.
The default is false, i.e. no sorting on insertion.
To set the sorting, use setSorting ().
访问函数:
| bool | sorting () const |
This property holds the space in pixels between icon view items.
The default is 5 pixels.
Negative values for spacing are illegal.
访问函数:
| int | spacing () const |
| virtual void | setSpacing (int sp ) |
This property holds whether the item text will be word-wrapped if it is too long.
默认为 true。
If this property is false, icon text that is too long is truncated, and an ellipsis (...) appended to indicate that truncation has occurred. The full text can still be seen by the user if they hover the mouse because the full text is shown in a tooltip; see setShowToolTips ().
访问函数:
| bool | wordWrapIconText () const |
| virtual void | setWordWrapIconText (bool b ) |
Constructs an empty icon view called name ,采用父级 parent and using the widget flags f .
[虚拟]
Q3IconView::
~Q3IconView
()
Destroys the icon view and deletes all items.
[virtual protected slot]
void
Q3IconView::
adjustItems
()
Adjusts the positions of the items to the geometry of the icon view.
[virtual slot]
void
Q3IconView::
arrangeItemsInGrid
(const
QSize
&
grid
,
bool
update
= true)
This variant uses grid instead of ( gridX (), gridY ())。若 grid is invalid (see QSize::isValid ()), arrangeItemsInGrid() calculates a valid grid itself and uses that.
若 update is true (the default) the viewport is repainted.
[virtual slot]
void
Q3IconView::
arrangeItemsInGrid
(
bool
update
= true)
这是重载函数。
Arranges all the items in the grid specified by gridX () 和 gridY ().
Even if sorting () is enabled, the items are not sorted by this function. If you want to sort or rearrange the items, use iconview->sort(iconview-> sortDirection ()).
若 update is true (the default), the viewport is repainted as well.
另请参阅 Q3IconView::setGridX (), Q3IconView::setGridY (),和 Q3IconView::sort ().
[virtual protected]
void
Q3IconView::
changeEvent
(
QEvent
*
ev
)
重实现自 QWidget::changeEvent ().
[虚拟]
void
Q3IconView::
clear
()
Clears the icon view. All items are deleted.
[虚拟]
void
Q3IconView::
clearSelection
()
Unselects all the items.
[signal]
void
Q3IconView::
clicked
(
Q3IconViewItem
*
item
)
This signal is emitted when the user clicks any mouse button. If item is non-null, the cursor is on item 。若 item is null, the mouse cursor isn't on any item.
注意: 信号 clicked 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)(Q3IconViewItem *)>(&Q3IconView::clicked), [=](Q3IconViewItem *item){ /* ... */ });
另请参阅 mouseButtonClicked (), rightButtonClicked (),和 pressed ().
[signal]
void
Q3IconView::
clicked
(
Q3IconViewItem
*
item
, const
QPoint
&
pos
)
这是重载函数。
This signal is emitted when the user clicks any mouse button on an icon view item. item is a pointer to the item that has been clicked.
pos is the position of the mouse cursor in the global coordinate system ( QMouseEvent::globalPos ()). (If the click's press and release differ by a pixel or two, pos is the position at release time.)
注意: 信号 clicked 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)(Q3IconViewItem *, const QPoint &)>(&Q3IconView::clicked), [=](Q3IconViewItem *item, const QPoint &pos){ /* ... */ });
另请参阅 mouseButtonClicked (), rightButtonClicked (),和 pressed ().
[virtual protected]
void
Q3IconView::
contentsContextMenuEvent
(
QContextMenuEvent
*
e
)
重实现自 Q3ScrollView::contentsContextMenuEvent ().
[virtual protected]
void
Q3IconView::
contentsDragEnterEvent
(
QDragEnterEvent
*
e
)
重实现自 Q3ScrollView::contentsDragEnterEvent ().
[virtual protected]
void
Q3IconView::
contentsDragLeaveEvent
(
QDragLeaveEvent
*
e
)
重实现自 Q3ScrollView::contentsDragLeaveEvent ().
[virtual protected]
void
Q3IconView::
contentsDragMoveEvent
(
QDragMoveEvent
*
e
)
重实现自 Q3ScrollView::contentsDragMoveEvent ().
[virtual protected]
void
Q3IconView::
contentsDropEvent
(
QDropEvent
*
e
)
重实现自 Q3ScrollView::contentsDropEvent ().
[virtual protected]
void
Q3IconView::
contentsMouseDoubleClickEvent
(
QMouseEvent
*
e
)
重实现自 Q3ScrollView::contentsMouseDoubleClickEvent ().
[virtual protected]
void
Q3IconView::
contentsMouseMoveEvent
(
QMouseEvent
*
e
)
重实现自 Q3ScrollView::contentsMouseMoveEvent ().
[virtual protected]
void
Q3IconView::
contentsMousePressEvent
(
QMouseEvent
*
e
)
重实现自 Q3ScrollView::contentsMousePressEvent ().
[virtual protected]
void
Q3IconView::
contentsMouseReleaseEvent
(
QMouseEvent
*
e
)
重实现自 Q3ScrollView::contentsMouseReleaseEvent ().
[signal]
void
Q3IconView::
contextMenuRequested
(
Q3IconViewItem
*
item
, const
QPoint
&
pos
)
This signal is emitted when the user invokes a context menu with the right mouse button or with special system keys, with item being the item under the mouse cursor or the current item, respectively.
pos is the position for the context menu in the global coordinate system.
[signal]
void
Q3IconView::
currentChanged
(
Q3IconViewItem
*
item
)
This signal is emitted when a new item becomes current. item is the new current item (or 0 if no item is now current).
另请参阅 currentItem ().
Returns a pointer to the current item of the icon view, or 0 if no item is current.
另请参阅 setCurrentItem (), firstItem (),和 lastItem ().
[virtual protected slot]
void
Q3IconView::
doAutoScroll
()
Performs autoscrolling when selecting multiple icons with the rubber band.
[signal]
void
Q3IconView::
doubleClicked
(
Q3IconViewItem
*
item
)
This signal is emitted when the user double-clicks on item .
[virtual protected]
Q3DragObject
* Q3IconView::
dragObject
()
返回 Q3DragObject that should be used for drag-and-drop. This function is called by the icon view when starting a drag to get the dragobject that should be used for the drag. Subclasses may reimplement this.
另请参阅 Q3IconDrag .
[virtual protected]
void
Q3IconView::
drawBackground
(
QPainter
*
p
, const
QRect
&
r
)
This function is called to draw the rectangle r of the background using the painter p .
默认实现填充 r with the viewport's backgroundBrush(). Subclasses can reimplement this to draw custom backgrounds.
另请参阅 drawContents ().
[virtual protected]
void
Q3IconView::
drawContents
(
QPainter
*
p
,
int
cx
,
int
cy
,
int
cw
,
int
ch
)
重实现自 Q3ScrollView::drawContents ().
[virtual protected]
void
Q3IconView::
drawRubber
(
QPainter
*
p
)
Draws the rubber band using the painter p .
[signal]
void
Q3IconView::
dropped
(
QDropEvent
*
e
, const
Q3ValueList
<
Q3IconDragItem
> &
lst
)
This signal is emitted when a drop event occurs in the viewport (but not on any icon) which the icon view itself can't handle.
e provides all the information about the drop. If the drag object of the drop was a Q3IconDrag , lst contains the list of the dropped items. You can get the data using Q3IconDragItem::data () on each item. If the lst is empty, i.e. the drag was not a Q3IconDrag , you have to decode the data in e and work with that.
Note Q3IconViewItems may be drop targets; if a drop event occurs on an item the item handles the drop.
[protected]
void
Q3IconView::
emitSelectionChanged
(
Q3IconViewItem
*
i
= 0)
Emits a signal to indicate selection changes. i 是 Q3IconViewItem that was selected or de-selected.
You should never need to call this function.
Makes sure that item is entirely visible. If necessary, ensureItemVisible() scrolls the icon view.
另请参阅 ensureVisible ().
[virtual protected]
void
Q3IconView::
enterEvent
(
QEvent
*
e
)
重实现自 QWidget::enterEvent ().
[虚拟]
bool
Q3IconView::
eventFilter
(
QObject
*
o
,
QEvent
*
e
)
重实现自 QObject::eventFilter ().
Finds the first item whose bounding rectangle overlaps r and returns a pointer to that item. r is given in content coordinates. Returns 0 if no item overlaps r .
If you want to find all items that touch r , you will need to use this function and nextItem() in a loop ending at findLastVisibleItem () and test Q3IconViewItem::rect () for each of these items.
另请参阅 findLastVisibleItem () 和 Q3IconViewItem::rect ().
Returns a pointer to the item that contains point pos , which is given in contents coordinates, or 0 if no item contains point pos .
这是重载函数。
Returns a pointer to the first item whose text begins with text , or 0 if no such item could be found. Use the compare flag to control the comparison behavior.
Finds the last item whose bounding rectangle overlaps r and returns a pointer to that item. r is given in content coordinates. Returns 0 if no item overlaps r .
另请参阅 findFirstVisibleItem ().
Returns a pointer to the first item of the icon view, or 0 if there are no items in the icon view.
另请参阅 lastItem () 和 currentItem ().
[virtual protected]
void
Q3IconView::
focusInEvent
(
QFocusEvent
*
e
)
重实现自 QWidget::focusInEvent ().
[virtual protected]
void
Q3IconView::
focusOutEvent
(
QFocusEvent
*
e
)
重实现自 QWidget::focusOutEvent ().
返回索引对于 item ,或 -1 若 item doesn't exist in this icon view.
[虚拟]
QVariant
Q3IconView::
inputMethodQuery
(
Qt::InputMethodQuery
query
) const
重实现自 QWidget::inputMethodQuery ().
[virtual protected]
void
Q3IconView::
insertInGrid
(
Q3IconViewItem
*
item
)
插入 Q3IconViewItem item in the icon view's grid. You should never need to call this function. Instead, insert Q3IconViewItems by creating them with a pointer to the Q3IconView that they are to be inserted into.
[虚拟]
void
Q3IconView::
insertItem
(
Q3IconViewItem
*
item
,
Q3IconViewItem
*
after
= 0L)
Inserts the icon view item item after after 。若 after 为 0, item is appended after the last item.
You should never need to call this function. Instead create Q3IconViewItem 's and associate them with your icon view like this:
(void) new Q3IconViewItem(myIconview, "The text of the item", aPixmap);
[虚拟]
void
Q3IconView::
invertSelection
()
Inverts the selection. Works only in Multi and Extended selection mode.
Returns true if an iconview item is being renamed; otherwise returns false.
[signal]
void
Q3IconView::
itemRenamed
(
Q3IconViewItem
*
item
, const
QString
&
name
)
此信号发射当 item has been renamed to name , usually by in-place renaming.
注意: 信号 itemRenamed 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)(Q3IconViewItem *, const QString &)>(&Q3IconView::itemRenamed), [=](Q3IconViewItem *item, const QString &name){ /* ... */ });
另请参阅 Q3IconViewItem::setRenameEnabled () 和 Q3IconViewItem::rename ().
[signal]
void
Q3IconView::
itemRenamed
(
Q3IconViewItem
*
item
)
这是重载函数。
此信号发射当 item has been renamed, usually by in-place renaming.
注意: 信号 itemRenamed 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)(Q3IconViewItem *)>(&Q3IconView::itemRenamed), [=](Q3IconViewItem *item){ /* ... */ });
另请参阅 Q3IconViewItem::setRenameEnabled () 和 Q3IconViewItem::rename ().
[virtual protected]
void
Q3IconView::
keyPressEvent
(
QKeyEvent
*
e
)
重实现自 QWidget::keyPressEvent ().
Returns a pointer to the last item of the icon view, or 0 if there are no items in the icon view.
另请参阅 firstItem () 和 currentItem ().
[protected]
Q3IconViewItem
* Q3IconView::
makeRowLayout
(
Q3IconViewItem
*
begin
,
int
&
y
,
bool
&
changed
)
Lays out a row of icons (if Arrangement == TopToBottom this is a column). Starts laying out with the item begin . y is the starting coordinate. Returns the last item of the row (column) and sets the new starting coordinate to y 。 changed parameter is used internally.
警告: This function may be made private in a future version of Qt. We do not recommend calling it.
[虚拟]
QSize
Q3IconView::
minimumSizeHint
() const
重实现自 QWidget::minimumSizeHint ().
[signal]
void
Q3IconView::
mouseButtonClicked
(
int
button
,
Q3IconViewItem
*
item
, const
QPoint
&
pos
)
This signal is emitted when the user clicks mouse button button 。若 item is non-null, the cursor is on item 。若 item is null, the mouse cursor isn't on any item.
pos is the position of the mouse cursor in the global coordinate system ( QMouseEvent::globalPos ()). (If the click's press and release differ by a pixel or two, pos is the position at release time.)
另请参阅 mouseButtonPressed (), rightButtonClicked (),和 clicked ().
[signal]
void
Q3IconView::
mouseButtonPressed
(
int
button
,
Q3IconViewItem
*
item
, const
QPoint
&
pos
)
This signal is emitted when the user presses mouse button button 。若 item is non-null, the cursor is on item 。若 item is null, the mouse cursor isn't on any item.
pos is the position of the mouse cursor in the global coordinate system ( QMouseEvent::globalPos ()).
另请参阅 rightButtonClicked (), mouseButtonClicked (),和 pressed ().
[signal]
void
Q3IconView::
moved
()
This signal is emitted after successfully dropping one (or more) items of the icon view. If the items should be removed, it's best to do so in a slot connected to this signal.
[signal]
void
Q3IconView::
onItem
(
Q3IconViewItem
*
item
)
This signal is emitted when the user moves the mouse cursor onto an item , similar to the QWidget::enterEvent () 函数。
[signal]
void
Q3IconView::
onViewport
()
This signal is emitted when the user moves the mouse cursor from an item to an empty part of the icon view.
另请参阅 onItem ().
[signal]
void
Q3IconView::
pressed
(
Q3IconViewItem
*
item
)
This signal is emitted when the user presses any mouse button. If item is non-null, the cursor is on item 。若 item is null, the mouse cursor isn't on any item.
注意: 信号 pressed 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)(Q3IconViewItem *)>(&Q3IconView::pressed), [=](Q3IconViewItem *item){ /* ... */ });
另请参阅 mouseButtonPressed (), rightButtonPressed (),和 clicked ().
[signal]
void
Q3IconView::
pressed
(
Q3IconViewItem
*
item
, const
QPoint
&
pos
)
这是重载函数。
This signal is emitted when the user presses any mouse button. If item is non-null, the cursor is on item 。若 item is null, the mouse cursor isn't on any item.
pos is the position of the mouse cursor in the global coordinate system ( QMouseEvent::globalPos ()). (If the click's press and release differ by a pixel or two, pos is the position at release time.)
注意: 信号 pressed 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)(Q3IconViewItem *, const QPoint &)>(&Q3IconView::pressed), [=](Q3IconViewItem *item, const QPoint &pos){ /* ... */ });
另请参阅 mouseButtonPressed (), rightButtonPressed (),和 clicked ().
[虚拟]
void
Q3IconView::
repaintItem
(
Q3IconViewItem
*
item
)
Repaints the item .
Repaints the selected items.
[virtual protected]
void
Q3IconView::
resizeEvent
(
QResizeEvent
*
e
)
重实现自 QWidget::resizeEvent ().
[signal]
void
Q3IconView::
returnPressed
(
Q3IconViewItem
*
item
)
This signal is emitted if the user presses the Return or Enter key. item 是 currentItem () at the time of the keypress.
[signal]
void
Q3IconView::
rightButtonClicked
(
Q3IconViewItem
*
item
, const
QPoint
&
pos
)
This signal is emitted when the user clicks the right mouse button. If item is non-null, the cursor is on item 。若 item is null, the mouse cursor isn't on any item.
pos is the position of the mouse cursor in the global coordinate system ( QMouseEvent::globalPos ()). (If the click's press and release differ by a pixel or two, pos is the position at release time.)
另请参阅 rightButtonPressed (), mouseButtonClicked (),和 clicked ().
[signal]
void
Q3IconView::
rightButtonPressed
(
Q3IconViewItem
*
item
, const
QPoint
&
pos
)
This signal is emitted when the user presses the right mouse button. If item is non-null, the cursor is on item 。若 item is null, the mouse cursor isn't on any item.
pos is the position of the mouse cursor in the global coordinate system ( QMouseEvent::globalPos ()).
[虚拟]
void
Q3IconView::
selectAll
(
bool
select
)
In Multi and Extended modes, this function sets all items to be selected if select is true, and to be unselected if select 为 false。
In Single and NoSelection modes, this function only changes the selection status of currentItem ().
[signal]
void
Q3IconView::
selectionChanged
()
This signal is emitted when the selection has been changed. It's emitted in each selection mode.
注意: 信号 selectionChanged 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)()>(&Q3IconView::selectionChanged), [=](){ /* ... */ });
[signal]
void
Q3IconView::
selectionChanged
(
Q3IconViewItem
*
item
)
这是重载函数。
This signal is emitted when the selection changes. item is the newly selected item. This signal is emitted only in single selection mode.
注意: 信号 selectionChanged 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:
connect(3IconView, static_cast<void(Q3IconView::*)(Q3IconViewItem *)>(&Q3IconView::selectionChanged), [=](Q3IconViewItem *item){ /* ... */ });
[virtual slot]
void
Q3IconView::
setContentsPos
(
int
x
,
int
y
)
重实现自 Q3ScrollView::setContentsPos ().
[虚拟]
void
Q3IconView::
setCurrentItem
(
Q3IconViewItem
*
item
)
使 item the new current item of the icon view.
另请参阅 currentItem ().
[虚拟]
void
Q3IconView::
setSelected
(
Q3IconViewItem
*
item
,
bool
s
,
bool
cb
= false)
Selects or unselects item 从属 s , and may also unselect other items, depending on Q3IconView::selectionMode () 和 cb .
若 s is false, item is unselected.
若 s is true and Q3IconView::selectionMode () 是 Single , item is selected, and the item which was selected is unselected.
若 s is true and Q3IconView::selectionMode () 是 Extended , item is selected. If cb is true, the selection state of the icon view's other items is left unchanged. If cb is false (the default) all other items are unselected.
若 s is true and Q3IconView::selectionMode () 是 Multi item 被选中。
注意, cb is used only if Q3IconView::selectionMode () 是 Extended . cb defaults to false.
All items whose selection status is changed repaint themselves.
若 sort is true, this function sets the icon view to sort items when a new item is inserted. If sort is false, the icon view will not be sorted.
注意, autoArrange () must be true for sorting to take place.
若 ascending is true (the default), items are sorted in ascending order. If ascending is false, items are sorted in descending order.
Q3IconViewItem::compare () is used to compare pairs of items. The sorting is based on the items' keys; these default to the items' text unless specifically set to something else.
另请参阅 sorting (), Q3IconView::setAutoArrange (), Q3IconView::autoArrange (), sortDirection (), sort (),和 Q3IconViewItem::setKey ().
[虚拟]
void
Q3IconView::
showEvent
(
QShowEvent
*)
重实现自 QWidget::showEvent ().
[虚拟]
QSize
Q3IconView::
sizeHint
() const
重实现自 QWidget::sizeHint ().
[virtual protected slot]
void
Q3IconView::
slotUpdate
()
This slot is used for a slightly-delayed update.
The icon view is not redrawn immediately after inserting a new item but after a very small delay using a QTimer . This means that when many items are inserted in a loop the icon view is probably redrawn only once at the end of the loop. This makes the insertions both flicker-free and faster.
[虚拟]
void
Q3IconView::
sort
(
bool
ascending
= true)
Sorts and rearranges all the items in the icon view. If ascending is true, the items are sorted in increasing order, otherwise they are sorted in decreasing order.
Q3IconViewItem::compare () is used to compare pairs of items. The sorting is based on the items' keys; these default to the items' text unless specifically set to something else.
Note that this function sets the sort order to ascending .
另请参阅 Q3IconViewItem::key (), Q3IconViewItem::setKey (), Q3IconViewItem::compare (), Q3IconView::setSorting (),和 Q3IconView::sortDirection ().
[virtual protected]
void
Q3IconView::
startDrag
()
Starts a drag.
[虚拟]
void
Q3IconView::
takeItem
(
Q3IconViewItem
*
item
)
Takes the icon view item item out of the icon view and causes an update of the screen display. The item is not deleted. You should normally not need to call this function because Q3IconViewItem::~Q3IconViewItem() calls it. The normal way to delete an item is to delete it.