I tried to reproduce your problem, but everything works fine for me. Here is what I did:
With Qt-Designer, I put a QTableView (called tbvTest ) in my form.
In the constructor of my form, this is what I wrote:
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); ui->tbvTest->setModel(new TableModel); QSettings MySetting(QSettings::IniFormat, QSettings::UserScope, "Test"); QByteArray MyArray = MySetting.value("column_width", "").toByteArray(); ui->tbvTest->horizontalHeader()->restoreState(MyArray); }
(note that in my main.cpp I set ApplicationName , OrganizationName and OrganizationDomain )
In the destructor of my form, here is what I wrote:
Widget::~Widget() { QByteArray MyArray = ui->tbvTest->horizontalHeader()->saveState(); QSettings MySetting(QSettings::IniFormat, QSettings::UserScope, "Test"); MySetting.setValue("column_width", MyArray); delete ui; }
If I launch the application and change the column width, close the application and run it again, the column width will be restored correctly.
Is there anything I do from you?
source share