What's the best way to use QTableWidgetItem(to don't waste space)
Solved
General and Desktop
-
Hey, I want to have a table in MainWindow and I do, but the problem is that it's going to use lots of space because every time loop is running a new QTableWidgetItem is getting another space.
void MainWindow::dispHelp() { int i, j, row, col, kk; QString test_str; row = 10; col = 5; for(i=0;i<row;i++) { for(j = 0; j<col; j++) { kk = i * (col) + j; test_str.setNum( kk,10); QTableWidgetItem* m_tblItem = new QTableWidgetItem; //What I want is to declare this "QTableWidgetItem* m_tblItem = new QTableWidgetItem;" once and use it as long as *for* is looping. m_tblItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); m_tblItem->setTextColor(Qt::black); m_tblItem->setText(test_str); ui->tbl_dbg->setItem(i,j, m_tblItem); } } }
Any help will be appreciated. Thanks!
-
@Muhammad-Mirab-Br said in What's the best way to use QTableWidgetItem(to don't waste space):
once and use it as long as for is looping.
How should this be possible? Every cell needs an own QTableWidgetItem.
For big tables I would suggest to not use the convenience view widgets but a custom model derived from QAbstractItemModel or QAbstractTableModel
-
This post is deleted!
-
@Christian-Ehrlicher Alright, thanks!