QListBoxItem(3qt)

NAME
QListBoxItem - This is the base class of all list box items

SYNOPSIS

#include <qlistbox.h>

Inherited by QListBoxPixmap and QListBoxText.

  Public Members
QListBoxItem ()
virtual ~QListBoxItem ()
virtual const char* text () const
virtual const QPixmap* pixmap () const
virtual int height ( const QListBox * ) const
virtual int width ( const QListBox * ) const

  Protected Members
virtual void paint ( QPainter * )
void setText ( const char * text )

DESCRIPTION
This is the base class of all list box items.

This class is the abstract base class of all list box items. If you need to insert customized items into a QListBox, you must inherit this class and reimplement paint(), height() and width().

The following shows how to define a list box item which shows a pixmap and a text:

    class MyListBoxItem : public QListBoxItem
    {
    public:
        MyListBoxItem( const char *s, const QPixmap p )
            : QListBoxItem(), pm(p)
            { setText( s ); }
    protected:
        virtual void paint( QPainter * );
        virtual int height( const QListBox * ) const;
        virtual int width( const QListBox * ) const;
        virtual const QPixmap *pixmap() { return &pm; }
    private:
        QPixmap pm;
    };
    void MyListBoxItem::paint( QPainter *p )
    {
        p->drawPixmap( 3, 0, pm );
        QFontMetrics fm = p->fontMetrics();
        int yPos;                       // vertical text position
        if ( pm.height() < fm.height() )
            yPos = fm.ascent() + fm.leading()/2;
        else
            yPos = pm.height()/2 - fm.height()/2 + fm.ascent();
        p->drawText( pm.width() + 5, yPos, text() );
    }
    int MyListBoxItem::height(const QListBox *lb ) const
    {
        return QMAX( pm.height(), lb->fontMetrics().lineSpacing() + 1 );
    }
    int MyListBoxItem::width(const QListBox *lb ) const
    {
        return pm.width() + lb->fontMetrics().width( text() ) + 6;
    }

See also: QListBox.

MEMBER FUNCTION DOCUMENTATION

QListBoxItem::QListBoxItem ()
Constructs an empty list box item.

QListBoxItem::~QListBoxItem () [virtual]
Destroys the list box item.

int QListBoxItem::height ( const QListBox * ) const [virtual]
Implement this function to return the height of your item

See also: paint() and width().

Reimplemented in QListBoxPixmap and QListBoxText.

void QListBoxItem::paint ( QPainter * p ) [virtual protected]
Implement this function to draw your item.

See also: height() and width().

Reimplemented in QListBoxPixmap and QListBoxText.

const QPixmap * QListBoxItem::pixmap () const [virtual]
Returns the pixmap connected with the item, if any.

The default implementation of this function returns a null pointer.

Reimplemented in QListBoxPixmap.

void QListBoxItem::setText ( const char * text ) [protected]
Sets the text of the widget, which is used for sorting. The text is not shown unless explicitly drawn in paint().

See also: text().

const char * QListBoxItem::text () const [virtual]
Returns the text of the item, which is used for sorting.

See also: setText().

int QListBoxItem::width ( const QListBox * ) const [virtual]
Implement this function to return the width of your item

See also: paint() and height().

Reimplemented in QListBoxPixmap and QListBoxText.

SEE ALSO
http://www.troll.no/qt/qlistboxitem.html

COPYRIGHT
Copyright 1992-1997 Troll Tech AS. See the LICENSE file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.