如何创建 QTableView 多行单元格?
我正在使用下面的代码填写表格。但是 WhemGetDescription()
返回一个长字符串,内容以...
有什么办法可以自动断线?
QStandardItemModel * model = new QStandardItemModel(logos.size(), 2, this);
model->setHorizontalHeaderItem(0, new QStandardItem(QString("")));
model->setHorizontalHeaderItem(1, new QStandardItem(QString("Nome")));
model->setHorizontalHeaderItem(2, new QStandardItem(QString("Descrição")));
int row = 0;
foreach(Item * item, items)
{
QStandardItem* check = new QStandardItem(true);
check->setCheckable(true);
model->setItem(row, 0, check);
QStandardItem *nameItem = new QStandardItem(QString(item->GetName()));
nameItem->setEditable(false);
model->setItem(row, 1, nameItem);
QStandardItem *descriptionItem = new QStandardItem(item->GetDescription());
descriptionItem->setEditable(false);
descriptionItem->setToolTip(logo->GetDescription());
model->setItem(row, 2, descriptionItem);
row++;
}
ui->tableView->setModel(model);
ui->tableView->resizeColumnToContents(0);
ui->tableView->resizeColumnToContents(1);
ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
ui->tableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
ui->tableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);