There is no easy way to do this. I suggest something like next:
Use vector to store logicalIndexes of moved headers.
QVector<int> last;
Use sectionMoved signal to detect moving and store logicalIndex in vector:
connect( ui->tableView->horizontalHeader(),static_cast<void (QHeaderView::*)(int,int,int)>(&QHeaderView::sectionMoved),[=](int logicalIndex, int oldVisualIndex, int newVisualIndex)
{//with lambda
//you can also provide shecking is current logicalIdnex already exist in vector
last.push_back(logicalIndex);
});
Syntax is so complicate and ugly because there is another sectionMoved in QHeaderView, so it is necessary. If you don't know new syntax, use old:
connect( ui->tableView->horizontalHeader(), SIGNAL(sectionMoved(int,int,int)), this, SLOT(yourSlot(int,int,int)));
But create yourSlot(int,int,int) and do last.push_back(logicalIndex); in this slot.
When you want saveState, hide all sections with logicalIndex which you store in vector and save it:
QByteArray array;
for(int i = 0; i < last.size(); i++)
{
ui->tableView->horizontalHeader()->hideSection(last.at(i));
}
array = ui->tableView->horizontalHeader()->saveState();
Add CONFIG += c++11 to the pro file if you want use new syntax and lambda.