PDA

View Full Version : Reg - Subclass of QListBoxItem



lawrence
6th January 2007, 13:22
I want to display some text as bold and some as normal in QListBox.

I created subclass inheriting the QListBoxItem class.

The code is


MyListBoxItem *l_item = new MyListBoxItem(Pointer of listbox, string);

Here I called the subclass.

The Subclass is as follows


class MyListBoxItem : public QListBoxItem
{
public:

MyListBoxItem(QListBox *a_listBox, QString a_string)
{
l_string = a_string;
l_manageUserListBox = a_listBox;
};

~MyListBoxItem()
{
};
void paint(QPainter *a)
{
QPainter a_painter(l_manageUserListBox);
QRect r ( 0, 0, width( listBox() ), height( listBox() ) );
QFont l_font;
l_font.setBold(true);
a_painter.setFont(l_font);
a_painter.drawText(r,Qt::AlignLeft, l_string, -1);
}
private:
QString l_string;
QListBox *l_manageUserListBox;
}

But i didn't work. Any suggetions will be helpful.

e8johan
6th January 2007, 14:18
The JSeries (http://www.digitalfanatics.org/e8johan/projects/jseries/index.html) implements a custom list view item for Qt 3. Perhaps you can find some inspiration there.