Add items to columns in QStandardItemModel

前端 未结 1 1315
梦如初夏
梦如初夏 2021-01-14 01:30

I am currently adding rows to my QTableView as such

QStandardItem* itm;
QStandardItemModel* model = new QStandardItemModel(this);
model->setC         


        
相关标签:
1条回答
  • 2021-01-14 01:58

    Calling appendRow(QStandardItem *) only adds a single item to the first column. You would need to pass in a QList to appendRow() to add items to each column, e.g.:

    QList<QStandardItem *> items;
    
    items.append(new QStandardItem("Column 1 Text"));
    items.append(new QStandardItem("Column 2 Text"));
    
    QStandardItemModel* model = new QStandardItemModel(this);
    
    model->setColumnCount(2);
    model->appendRow(items);
    

    See http://doc.qt.io/qt-5/qstandarditemmodel.html#appendRow for more detail.

    0 讨论(0)
提交回复
热议问题