Hi again Vronin;
I improve little bit your idea. Perphaps is usefull for somebody.
As I comment before, my tableview will have diferent types of Aligment. Some columns goes to right, other left, other center.
But, I will use the same subclass created for QSqlQueryModel I will call this subclass many times in diferent part of my application.
I created something more variable, so at the moment that you call the subclass you must define by QStringList define in my subclass, for each column what kind of aligment you like.
Thanks Vronin for your help. And I share the code with you
================== MyQSqlQueryModel.h ======================
#ifndef MYQSQLQUERYMODEL_H
#define MYQSQLQUERYMODEL_H
#include <QSqlQueryModel>
#include <QObject>
class MyQSqlQueryModel : public QSqlQueryModel
{
public:
MyQSqlQueryModel();
QVariant data(const QModelIndex &item, int role) const;
QStringList AligmentDefinition; // HERE I DEFINE THE ALIGMENT BY COLUMNS
};
#endif // MYQSQLQUERYMODEL_H
================== MyQSqlQueryModel.cpp ======================
#include "myqsqlquerymodel.h"
MyQSqlQueryModel::MyQSqlQueryModel()
{
}
QVariant MyQSqlQueryModel::data(const QModelIndex &item, int role) const
{
if(role==Qt::TextAlignmentRole)
{
if(AligmentDefinition.size()==0)
{// There are any definition
return 0;
}
if(item.column() > AligmentDefinition.size())
{// There are no definition for that Column
return 0;
}
int i = item.column();
QString Value = AligmentDefinition.value(i);
if(Value =="1")
return int(Qt::AlignRight | Qt::AlignVCenter);
if(Value=="2")
return int(Qt::AlignCenter | Qt::AlignVCenter);
if(Value=="3")
return int(Qt::AlignLeft | Qt::AlignVCenter);
}
return QSqlQueryModel::data(item,role);
}
=============== MAIN PROGRAM =======================
MyQSqlQueryModel *model = new MyQSqlQueryModel;
model->setQuery("SELECT * FROM SPSSourceLines");
model->AligmentDefinition << "1" << "2" << "3";
QModelIndex index;
index = model->index(0,0);
model->data(index,7);