{
if((dispItem = tW->item(row, col)) == 0) { // if no item set then insert new one
if((row == 0) || (col == 0)) {
L->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
L->setText(str) ;
L
->setFrameShape
(QFrame::StyledPanel);
L->setAutoFillBackground(true);
L->setPalette(P) ;
tW->setCellWidget(row, col, L) ;
}
else {
tW->setItem(row, col, newItem) ;
newItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter) ;
}
}
else { // existing cell, update contents
if((row == 0) || (col == 0)) {
QLabel *L
= qobject_cast<QLabel
*>
(tW
->cellWidget
(row, col
)) ;
// header L->setText(str);
}
else
dispItem->setText(str) ; // cell
}
}
void MainWindow::setTableWidgetString(QTableWidget *tW, int row, int col, QString str)
{
QTableWidgetItem *dispItem ;
if((dispItem = tW->item(row, col)) == 0) { // if no item set then insert new one
if((row == 0) || (col == 0)) {
QLabel *L = new QLabel() ; // new header
L->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
L->setText(str) ;
L->setFrameShape(QFrame::StyledPanel);
L->setAutoFillBackground(true);
L->setBackgroundRole(QPalette::Window);
QPalette P ;
P.setBrush(QPalette::Active, QPalette::Window, QBrush(Qt::lightGray));
L->setPalette(P) ;
tW->setCellWidget(row, col, L) ;
}
else {
QTableWidgetItem *newItem = new QTableWidgetItem(str) ; // new cell
tW->setItem(row, col, newItem) ;
newItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter) ;
}
}
else { // existing cell, update contents
if((row == 0) || (col == 0)) {
QLabel *L = qobject_cast<QLabel *> (tW->cellWidget(row, col)) ; // header
L->setText(str);
}
else
dispItem->setText(str) ; // cell
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks