PDA

View Full Version : Invisible custom qheaderview with checkbox and text



Morla
14th January 2014, 19:44
Hey,
i need header in table with checkbox and text. I did something this:

QStandardItemModel *model = new QStandardItemModel(this);

ui->tableView->setModel(model);

QtCheckHeaderView *header = new QtCheckHeaderView(Qt::Horizontal, ui->tableView);


QtCheckHeaderView *vheader = new QtCheckHeaderView(Qt::Vertical, ui->tableView);

ui->tableView->setHorizontalHeader(header);
ui->tableView->setVerticalHeader(vheader);

QStandardItem *root = model->invisibleRootItem();
QList<QList<QStandardItem *> > items;
for (int i = 0; i < 10; ++i)
{
QList<QStandardItem *> res;
for (int j = 0; j < 1000; ++j)
{
res.append(new QStandardItem(QString("%1;%2").arg(j).arg(i)));
vheader->addCheckable(j);
}
items.append(res);
root->appendColumn(res);

header->addCheckable(i);
}

This work good, i have horizontal and vertical header with checkbox and text but this only works if i put this code to MainWindow constructor.
If i put this code to for example pushbutton function it wont work. Datas are fine but headers are invisible.

ui->tableView->repaint();
won't work.
Someone maybe knows the answer why this is happening and/or how to solve this?
thanks for answer