im doing simple pagination with QSqlQueryModel select from limit query’s
every thing is working fine . but. now i like to reflect the Vertical headerData of the QTableView .
im implementing the headerData , beacose it is const function i can’t do any calculation inside it . so i have problem to calculate the right numbers in the Vertical headers. for example is im getting the rows from 20 to 30 .
i like the Vertical header show the numbers 20 to 30 . and so on …
this is how i implement the headerData :
QVariant PlayListSqlModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Vertical && role == Qt::DisplayRole)
{
return section;
}
if (role == Qt::DisplayRole)
{
if (orientation == Qt::Horizontal) {
switch (section)
{
case 0:
return QString("name");
case 1:
return QString("From");
case 2:
return QString("Created Time");
case 3:
return QString("last name");
case 4:
}
}
}
return QVariant();
}
UPDATE:
i even try to call const function that do the calculate , but still i have compilation error on the new const function :
error C2166: l-value specifies const object
int PlayListSqlModel::calculateVerticalHeader() const
{
int returnHeaderCount = m_iHeaderCount;
m_iHeaderCount++;
return returnHeaderCount;
}
QVariant PlayListSqlModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Vertical && role == Qt::DisplayRole)
{
return calculateVerticalHeader();
}
if (role == Qt::DisplayRole)
{
if (orientation == Qt::Horizontal) {
switch (section)
{
case 0:
return QString("Clip");
case 1:
return QString("From");
case 2:
return QString("Created Time");
case 3:
return QString("Rating");
case 4:
return QString("Feed");
case 5:
return QString("Double click to watch");
}
}
}
return QVariant();
}
As long as you have an accessible member variable containing the current page you could simply multiply it with the number of rows per page + row.
But as Alxx said, you thinking that you can’t do any calculations is probably because you fail to call non const methods that return the variables i used in the example above, right?
Update
The reason you get error C2166: l-value specifies const object is because you try to increment the class variable: m_iHeaderCount++ which is not allowed within a const declarated method. You may modify local variables within the headerData method but not class variables.