PDA

View Full Version : QAbstractTableModel, QTableView and restoreState.



cydside
10th August 2014, 11:41
Hi to all,
I used to save the QTableView horizontalHeader through saveState() and restore it by restoreState(...toByteArray()).
The model usually associated is a QSqlQueryModel. Now my QTableView is filled with a custom model inherited from QAbstractTableModel.



#ifndef CARTMODEL_H
#define CARTMODEL_H

#include <QtWidgets>
#include "ItemsCart.h"

class ItemsCart;

class CartModel : public QAbstractTableModel
{
Q_OBJECT

public:
CartModel(QObject *parent);

void setCart(ItemsCart *inItemsCart);

int rowCount(const QModelIndex &parent = QModelIndex()) const ;

int columnCount(const QModelIndex &parent = QModelIndex()) const;

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;

QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

protected:
ItemsCart *mItemsCart;
};

#endif


The problem I have is that restoreState() restore nothing, instead clears or hides all the horizontal headers.
Should I miss a function to reimplement?

Thanks in advance,

Danilo