typedef QList<int> MyList;Q_DECLARE_METATYPE(MyList)
QList<QVariant> widthColumns;for(int numCol = 0; numCol < ui->tableWidget->columnCount(); numCol++) widthColumns << ui->tableWidget->columnWidth(numCol);settings.setValue("/widthColumns", widthColumns);
QList<QVariant> widthColumns = settings.value("/widthColumns").toList();for(int numCol = 0; numCol < widthColumns.size(); numCol++) ui->tableWidget->setColumnWidth(numCol, widthColumns[numCol].toInt());
C++ (Qt)template <class View>void saveColumnWidthes (QSettings &settings, View *v){ settings.beginWriteArray (v->objectName ()); for (int i = 0, count =v->model ()->columnCount (); i < count; ++i) { settings.setArrayIndex (i); settings.setValue ("Width", v->columnWidth (i)); } settings.endArray ();} template <class View>void restoreColumnWidthes (QSettings &settings, View *v){ const int count = settings.beginReadArray (v->objectName ()); for (int i = 0; i < count; ++i) { settings.setArrayIndex (i); v->setColumnWidth (i, settings.value ("Width").toInt ()); } settings.endArray ();}
for (int i = 0, count =v->model ()->columnCount (); i < count; ++i) {