Ashkan_s
19th September 2012, 08:54
I have a QTableView wich its corner button is enabled. Problem is when I click the button, only a portion of rows gets selected -in my case the first 256 rows, which are the currently loaded rows.
Here is an example:
#include <QtGui>
#include <QtSql>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("D:\\tempDB\\mydb");
if (db.open()) {
QSqlQuery query;
QString str = "title";
query.exec("CREATE TABLE " + str + "(\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
title1 VARCHAR(255),\
title2 VARCHAR(255))");
QSqlTableModel model;
model.setTable("title");
model.setEditStrategy(QSqlTableModel::OnManualSubm it);
QSqlRecord rec1 = db.record("title");
QSqlRecord rec4, rec3, rec2;
rec4 = rec3 = rec2 = rec1;
rec1.setValue("title1", "test1");
rec1.setValue("title2", "test11");
rec2.setValue("title1", "test2");
rec2.setValue("title2", "test22");
rec3.setValue("title1", "test3");
rec3.setValue("title2", "test33");
rec4.setValue("title1", "test4");
rec4.setValue("title2", "test44");
db.transaction();
model.insertRows(0, 1024);
for (int i = 0; i < 1024;)
{
model.setRecord(i++, rec1);
model.setRecord(i++, rec2);
model.setRecord(i++, rec3);
model.setRecord(i++, rec4);
}
model.submitAll();
db.commit();
model.select();
QTableView view;
view.setModel(&model);
view.resize(640, 480);
view.setCornerButtonEnabled(true);
view.show();
return app.exec();
}
else
{
return 1;
}
}
Running this example, clicking the corner button before scrolling down the view to the bottom, then scrolling the view down, will reproduce the problem.
Added after 18 minutes:
I know I can force the model to fetch all the data by putting
while (model.canFetchMore())
model.fetchMore();
in the code, but shouldn't it load all when I click the corner button?
Here is an example:
#include <QtGui>
#include <QtSql>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("D:\\tempDB\\mydb");
if (db.open()) {
QSqlQuery query;
QString str = "title";
query.exec("CREATE TABLE " + str + "(\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
title1 VARCHAR(255),\
title2 VARCHAR(255))");
QSqlTableModel model;
model.setTable("title");
model.setEditStrategy(QSqlTableModel::OnManualSubm it);
QSqlRecord rec1 = db.record("title");
QSqlRecord rec4, rec3, rec2;
rec4 = rec3 = rec2 = rec1;
rec1.setValue("title1", "test1");
rec1.setValue("title2", "test11");
rec2.setValue("title1", "test2");
rec2.setValue("title2", "test22");
rec3.setValue("title1", "test3");
rec3.setValue("title2", "test33");
rec4.setValue("title1", "test4");
rec4.setValue("title2", "test44");
db.transaction();
model.insertRows(0, 1024);
for (int i = 0; i < 1024;)
{
model.setRecord(i++, rec1);
model.setRecord(i++, rec2);
model.setRecord(i++, rec3);
model.setRecord(i++, rec4);
}
model.submitAll();
db.commit();
model.select();
QTableView view;
view.setModel(&model);
view.resize(640, 480);
view.setCornerButtonEnabled(true);
view.show();
return app.exec();
}
else
{
return 1;
}
}
Running this example, clicking the corner button before scrolling down the view to the bottom, then scrolling the view down, will reproduce the problem.
Added after 18 minutes:
I know I can force the model to fetch all the data by putting
while (model.canFetchMore())
model.fetchMore();
in the code, but shouldn't it load all when I click the corner button?