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);
MyListBoxItem *l_item = new MyListBoxItem(Pointer of listbox, string);
To copy to clipboard, switch view to plain text mode
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()
{
};
{
QPainter a_painter
(l_manageUserListBox
);
QRect r
( 0,
0, width
( listBox
() ), height
( listBox
() ) );
l_font.setBold(true);
a_painter.setFont(l_font);
a_painter.drawText(r,Qt::AlignLeft, l_string, -1);
}
private:
QListBox *l_manageUserListBox;
}
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;
}
To copy to clipboard, switch view to plain text mode
But i didn't work. Any suggetions will be helpful.
Bookmarks