Qt logo

QIconViewItem Class Reference


The QIconViewItem class implements an iconview item. More...

#include <qiconview.h>

List of all member functions.

Public Members

Protected Members


Detailed Description

The QIconViewItem class implements an iconview item.

An iconview item is a object containing an icon and a text, which can display itself in an iconview.

The most simple way to create an iconview item and insert it into an iconview is, to construct it with a pointer to the iconview, a string and an icon:

    // parent is a pointer to our iconview, pixmap a QPixmap,
    // which we want to use as icon
    (void) new QIconViewItem( parent,
                              "This is the text of the item",
                              pixmap );

When the iconview is deleted, all items of it are deleted automatically, so the programmer must not delete the iconview items itself.

To iterate over all items of an iconview do something like

    QIconViewItem *item;
    for ( item = iconview->firstItem(); item; item = item->nextItem() )
      do_something_with( item );

To remove an item from an iconview, just delete the item. The destructor of the QIconViewItem does all the work for removing it from the iconview.

As the iconview is designed to use DnD, the iconview item has methods for DnD too which may be reimplemented.

Subclassing QIconViewItem will provide a big flexibility.

Examples: iconview/main.cpp


Member Function Documentation

QIconViewItem::QIconViewItem ( QIconView * parent )

Constructs an iconview item with no text and a default icon, and inserts it into the iconview parent.

QIconViewItem::QIconViewItem ( QIconView * parent, QIconViewItem * after )

Constructs an iconview item with no text and a default icon, and inserts it into the iconview parent after the iconview item after.

QIconViewItem::QIconViewItem ( QIconView * parent, QIconViewItem * after, const QString & text )

Constructs an iconview item using text as text and a default icon, and inserts it into the iconview parent after the iconview item after.

QIconViewItem::QIconViewItem ( QIconView * parent, QIconViewItem * after, const QString & text, const QPixmap & icon )

Constructs an iconview item using text as text and a \icon as icon, and inserts it into the iconview parent after the iconview item after.

QIconViewItem::QIconViewItem ( QIconView * parent, const QString & text )

Constructs an iconview item using text as text and a default icon, and inserts it into the iconview parent.

QIconViewItem::QIconViewItem ( QIconView * parent, const QString & text, const QPixmap & icon )

Constructs an iconview item using text as text and a \icon as icon, and inserts it into the iconview parent.

QIconViewItem::~QIconViewItem () [virtual]

Destructs the iconview item and tells the iconview about it.

bool QIconViewItem::acceptDrop ( const QMimeSource * mime ) const [virtual]

Returns TRUE, of the item accepts the QMimeSource mime (so it could be dropped on the item), else FALSE is returned.

The default implementation does nothing and returns always TRUE. A subclass should reimplement this to allow dropping something on an item.

void QIconViewItem::calcRect ( const QString & text_ = QString::null ) [virtual protected]

Recalculates the bounding rect, text- and pixmap-rect of the item.

int QIconViewItem::compare ( QIconViewItem * i ) const [virtual]

Compares this iconview item to i. Returns -1 if this item is less than i, 0 if they are equal and 1 if this iconview item is greater than i.

The default implementation uses QIconViewItem::key() to compare the items. A reimplementation may use different values.

See also: key().

bool QIconViewItem::contains ( QPoint pnt ) const

Returns TRUE, if the item contains the point pnt (in contents coordinates).

bool QIconViewItem::dragEnabled () const

Returns TRUE, if the user is allowed to drag the iconview item, else FALSE.

See also: setDragEnabled().

void QIconViewItem::dragEntered () [virtual protected]

This method is called, when a drag entered the item's bounding rect.

The default implementation does nothing, subcasses should reimplement this method.

void QIconViewItem::dragLeft () [virtual protected]

This method is called, when a drag left the item's bounding rect.

The default implementation does nothing, subcasses should reimplement this method.

bool QIconViewItem::dropEnabled () const

Returns TRUE, if the user is allowed to drop something onto the item, otherwise FALSE.

See also: setDropEnabled().

void QIconViewItem::dropped ( QDropEvent * e, const QValueList<QIconDragItem> & lst ) [virtual protected]

This method is called, when something was dropped on the item. e gives you all information about the drop. If the drag object of the drop was a QIconDrag, lst contains the list of the dropped items. You can get the data using QIconDragItem::data() of each item then.

So, if lst is not empty, use this data for further operations, else the drag was not a QIconDrag, so you have to decode e yourself and work with that.

The default implementation does nothing, subclasses should reimplement this method.

int QIconViewItem::height () const

Returns the height of the item.

QIconView * QIconViewItem::iconView () const

Returns a pointer to the iconview of this item.

int QIconViewItem::index () const

Returns the index of this item in the iconview, of -1 if something went wrong.

void QIconViewItem::init ( QIconViewItem * after = 0 ) [virtual protected]

Initializes the iconview item and inserts it into the iconview.

bool QIconViewItem::intersects ( QRect r ) const

Returns TRUE, if the item intersects the rectangle r (in contents coordinates).

bool QIconViewItem::isSelectable () const

Returns TRUE, of the item is selectable, else FALSE.

See also: setSelectable().

bool QIconViewItem::isSelected () const

Returns TRUE, if the item is selected, else FALSE.

See also: setSelected().

QString QIconViewItem::key () const [virtual]

Returns the key of the iconview item.

See also: setKey() and compareItems().

void QIconViewItem::move ( int x, int y ) [virtual]

Moves the item to x and y in the iconview (these are contents coordinates).

void QIconViewItem::move ( const QPoint & pnt ) [virtual]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QIconViewItem::moveBy ( int dx, int dy ) [virtual]

Moves the item by the distance dx and dy.

void QIconViewItem::moveBy ( const QPoint & pnt ) [virtual]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

QIconViewItem * QIconViewItem::nextItem () const

Returns a pointer to the next item, or 0 if this is the last item of the iconview.

void QIconViewItem::paintFocus ( QPainter * p, const QColorGroup & cg ) [virtual protected]

Paints the focus rect of the item using the painter p and the color group cg.

void QIconViewItem::paintItem ( QPainter * p, const QColorGroup & cg ) [virtual protected]

Paints the item using the painter p, the color group cg. If you want, that your iconview item is drawn with a different font or color, reimplement this method and change the values of the color group or the painter's font and call then the paintItem() method of the super class with the changed values.

QPixmap * QIconViewItem::pixmap () const [virtual]

Returns the icon of the iconview item. Normally you will set the pixmap if the item with setPixmap(), but somethimes you don't want that every item stores a copy of a pixmap or that you need to call setPixmap() for each item, so you can reimplement this method and return the pointer to the item pixmap directly here. If you do this you have to call calcRect() manually each time the size of this pixmap changes!

See also: setPixmap().

QRect QIconViewItem::pixmapRect ( bool relative = TRUE ) const

Returns the rectangle of the icon of the item. If relative is FALSE, the returned rectangle is relative to the origin of the contents' coordinate system, else the rectangle is relative to the origin of the item's rectangle.

QPoint QIconViewItem::pos () const

Returns the position of the item (in contents coordinates).

QIconViewItem * QIconViewItem::prevItem () const

Returns a pointer to the previous item, or 0 if this is the first item of the iconview.

QRect QIconViewItem::rect () const

Returns the bounding rect of the item (in contents coordinates).

void QIconViewItem::removeRenameBox () [virtual protected]

Removed the editbox which was used for in-place renaming.

void QIconViewItem::rename ()

Starts renaming an icon.

bool QIconViewItem::renameEnabled () const

Returns TRUE, if the item can be renamed ny the user with in-place renaming, else FALSE.

See also: setRenameEnabled().

void QIconViewItem::repaint () [virtual]

Repaints the item.

void QIconViewItem::setDragEnabled ( bool allow ) [virtual]

If allow is TRUE, the iconview lets the user to drag the iconview item (inside the iconview and outside of it). if allow is FALSE, no dragging is possible with this item.

void QIconViewItem::setDropEnabled ( bool allow ) [virtual]

If allow is TRUE, the iconview lets the use drop something on this iconview item.

void QIconViewItem::setItemRect ( const QRect & r ) [protected]

Sets the bounding rectangle of the whole item. This should be only used in subclasses, which reimplement calcRect() to be able to set the calcualted rectangle.

void QIconViewItem::setKey ( const QString & k ) [virtual]

Sets k as key of the iconview item. This is used for sorting.

See also: compareItems().

void QIconViewItem::setPixmap ( const QPixmap & icon ) [virtual]

Sets icon as item icon of the iconview item. This method might be a no-op if you reimplement pixmap().

See also: pixmap().

void QIconViewItem::setPixmap ( const QPixmap & icon, bool recalc, bool redraw = TRUE ) [virtual]

Sets icon as item icon of the iconview item. Using recalc you can specify, if the iconview should be recalculated and using redraw if it should be repainted or not.

This method might be a no-op if you reimplement pixmap().

See also: pixmap().

void QIconViewItem::setPixmapRect ( const QRect & r ) [protected]

Sets the bounding rectangle of the item icon. This should be only used in subclasses, which reimplement calcRect() to be able to set the calcualted rectangle.

void QIconViewItem::setRenameEnabled ( bool allow ) [virtual]

If \allow is TRUE, the user can rename the iconview item, when clicking on the text after the item has been selected (in-place renaming). If allow is FALSE, no inplace-renaming is done.

Examples: iconview/main.cpp

void QIconViewItem::setSelectable ( bool s ) [virtual]

If s is TRUE, this item can be selected, else it can't be selected.

void QIconViewItem::setSelected ( bool s ) [virtual]

Selects / Unselects the item depending on the QIconView::selectionMode() of the iconview.

The item redraws itself if the selection changed.

void QIconViewItem::setSelected ( bool s, bool cb ) [virtual]

Selects / Unselects the item depending on the QIconView::selectionMode() of the iconview.

If s is FALSE, the item gets unselected. If s is TRUE

  • and QIconView::selectionMode() is Single, the item gets selected and the item which was selected, gets unselected
  • and QIconView::selectionMode() is Extended item gets selected, and if cb is TRUE, the other items of the iconview are not touched, else they are all unselected.
  • and QIconView::selectionMode() is Multi the item gets selected.

    The item redraws itself if the selection changed.

    void QIconViewItem::setText ( const QString & text ) [virtual]

    Sets text as text of the iconview item. This method might be a no-op if you reimplement text().

    See also: text().

    void QIconViewItem::setText ( const QString & text, bool recalc, bool redraw = TRUE ) [virtual]

    Sets text as text of the iconview item. Using recalc you can specify, if the iconview should be recalculated and using redraw if it should be repainted or not.

    This method might be a no-op if you reimplement text().

    See also: text().

    void QIconViewItem::setTextRect ( const QRect & r ) [protected]

    Sets the bounding rectangle of the item text. This should be only used in subclasses, which reimplement calcRect() to be able to set the calcualted rectangle.

    void QIconViewItem::setView ( QIconView * v ) [protected]

    Sets the iconview of the item ot v. Normally you should not make use of this methode, only if you really know what you are doing!.

    QSize QIconViewItem::size () const

    Returns the size of the item.

    QString QIconViewItem::text () const [virtual]

    Returns the text of the iconview item. Normally you will set the text if the item with setText(), but somethimes you don't want to call setText/) for each item, so you can reimplement this method and return the text of the item directly here. If you do this you have to call calcRect() manually each time the text (and so the size of it) changes.

    See also: setText().

    QRect QIconViewItem::textRect ( bool relative = TRUE ) const

    Returns the rectangle of the text of the item. If relative is FALSE, the returned rectangle is relative to the origin of the contents' coordinate system, else the rectangle is relative to the origin of the item's rectangle.

    int QIconViewItem::width () const

    Returns the width of the item.

    int QIconViewItem::x () const

    Returns the X-Coordinate of the item (in contents coordinates).

    int QIconViewItem::y () const

    Returns the Y-Coordinate of the item (in contents coordinates).

    void QIconViewItem::calcTmpText () [protected]

    For internal use only.


    Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


    This file is part of the Qt toolkit, copyright © 1995-2000 Troll Tech, all rights reserved.


    Copyright İ 2000 Troll TechTrademarks
    Qt version 2.1.0-beta1