PDA

View Full Version : Q3listbox center items



sreedhar
24th February 2006, 11:24
Hi,
i am using Qt4.1. I have a Q3ListBox, and i want to align the items in the box, to the right or to the center.

Please reply me.

regards,
sree

jpn
24th February 2006, 11:40
Inherit Q3ListBoxItem and override:
void Q3ListBoxItem::paint ( QPainter * p ) [pure virtual protected]

In paint(), you can draw aligned text with:
void QPainter::drawText ( const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption() )

by supplying a QTextOption whose text aligment has been set to your like.

sreedhar
24th February 2006, 12:19
Thanks a lot it works fine

sreedhar
24th February 2006, 12:21
The same can be done also with
void QPainter::drawText ( const QRect & r, int flags, const QString & str, QRect * br = 0 )
where the flags can be used for alignment

sree