PDA

View Full Version : MyQListBoxItem doesn't draw



codebehind
25th June 2007, 14:47
The code of the paint function is this:

void MyLBItem::paint(QPainter *p)
{
// evil trick: find out whether we are painted onto our listbox
bool in_list_box = listBox() && listBox()->viewport() == p->device();

QRect r( 0, 0, listBox()->width(), listBox()->height( ) );
//p->drawText(r,Qt::AlignLeft, "new item", -1);
p->drawText(10,10,"new item", -1);
qDebug("Drawing text");
}


main function is:

int main(int argc, char **argv)
{
QApplication a(argc,argv);

QListBox lb;
MyLBItem lbiE(&lb);

lb.setGeometry(100,100,200,200);
lb.insertItem(&lbiE);
// lbiE.SetName("item 1");

a.setMainWidget(&lb);

lb.show();
// lb.repaint();

return a.exec();
}


when i run the app, the text doesn't show, nor the debug message. any clue?

jpn
25th June 2007, 16:02
when i run the app, the text doesn't show, nor the debug message. any clue?
Is MyLBItem::paint() private?

codebehind
28th June 2007, 21:35
paint() is protected

codebehind
4th July 2007, 15:25
After a long time...
I've found the problem. I haven't implemented the height() and width() functions. That is well documented in the Qt documentation. It shall be as simple as RTFM. :P
It works.