This is the base class of all list box items. More...
#include <qlistbox.h>
Inherited by QListBoxPixmap and QListBoxText.
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 ± } 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.
Constructs an empty list box item.
[virtual]
Destroys the list box item.
[virtual]
Implement this function to return the height of your item
See also: paint() and width().
Reimplemented in QListBoxPixmap and QListBoxText.
[virtual protected]
Implement this function to draw your item.
See also: height() and width().
Reimplemented in QListBoxPixmap and QListBoxText.
[virtual]
Returns the pixmap connected with the item, if any.
The default implementation of this function returns a null pointer.
Reimplemented in QListBoxPixmap.
[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().
[virtual]
Returns the text of the item, which is used for sorting.
See also: setText().
[virtual]
Implement this function to return the width of your item
See also: paint() and height().
Reimplemented in QListBoxPixmap and QListBoxText.
Search the documentation, FAQ, qt-interest archive and more (uses
www.troll.no):
This file is part of the Qt toolkit, copyright © 1995-98 Troll Tech, all rights reserved.
It was generated from the following files:
Copyright İ 1998 Troll Tech | Trademarks | Qt version 1.42
|