PDA

View Full Version : Text in QTableView cells not visible



juliarg
22nd March 2007, 14:26
Hello everyone, I have a problem with displaying item text in QTableView.
I created a QTableView widget using QT Designer and I am trying to make it dsplay a model.
I've created a model and set it to a view, the view doesn't display the text of the items, though it does show the same amount of empty columns and rows as the model contains. For example, I do this:


ui.setupUi((QMainWindow *)this);
QStandardItemModel model(2, 2);
QString st;
st.append("whee");
QStandardItem *item = new QStandardItem(st);
item->setText(st);
model.setItem(0, 0, item);
QStandardItem * item2 = model.item(0,0);
QString st2 = item2->text();

ui.tableView->setModel(&model);
ui.tableView->show();

The item text is getting returned correctly, but I can't see this text in a cell. What am I doing wrong?

jpn
22nd March 2007, 14:29
The item text is getting returned correctly, but I can't see this text in a cell. What am I doing wrong?
The model goes out of the scope and is destroyed as soon as the constructor ends. Create the model with operator "new".

juliarg
22nd March 2007, 15:49
Thanks for pointing that out! What a stupid bug :o