PDA

View Full Version : QLable::setText(text) is not showing the Text



ranna
12th November 2008, 16:21
HI,

I have an issue with QLable. I am creating the QLable object dynamically and after that i am adding it in a QTableWidget's cell (row x, colum 0);

Before adding the QLable into the TableWidget i am doing the following things.

{
QString lblNumber;
int nIndex = 0;
lblNumber.setNum(nIndex+1);
QLable *lblNo = new QLable(frame1);
lblNo->setAlignment(Qt::AlignCenter);
lblNo->setText(lblNumber);

tblwdgt->setCellWidget(row, 0, lblNo);
}

If i execute the application the lable's text is not visible to me.

Kindly help me to identify the actual root cause of this issue.

Thanks
Ranna
}

spirit
12th November 2008, 16:31
this code works fine for me


...
QVBoxLayout *vb = new QVBoxLayout();

QTableWidget *tv = new QTableWidget();
tv->setRowCount(10);
tv->setColumnCount(10);

for (int row = 0; row < tv->rowCount(); ++row) {
for (int column = 0; column < tv->columnCount(); ++column) {
QLabel *l = new QLabel();
l->setAlignment(Qt::AlignCenter);
l->setText("<b>Hello</b>");
tv->setCellWidget(row, column, l);
}
}

vb->addWidget(tv);

setLayout(vb);
...

anyway, why do you use this approach?

lyuts
12th November 2008, 22:31
What if you do this ?


{
int nIndex = 0;

// whatever you do with nIndex
// you incremented it by 1, we'll do the same
nIndex++;

QLable *lblNo = new QLable(frame1);
lblNo->setAlignment(Qt::AlignCenter);
lblNo->setText(QString::number(nIndex));

tblwdgt->setCellWidget(row, 0, lblNo);
}

ranna
14th November 2008, 10:20
I have tred the both solutions by adding the TableWidget in Layour and
lblNo->setText(QString::number(nIndex)); But it is not working and still i am facing the same problem.

spirit
14th November 2008, 10:39
ok, could you attach compilable example which represent this issue?