Chart Info: http://www.ics.com/files/qtdocs/itemviews-chart.html
I have copied Pieview.h and .cpp. I keep my data in a vector, so don't need chart.qrc.
My Abstract Model def:
absModel->setHeaderData(0, Qt::Horizontal, tr("Age"));
absModel->setHeaderData(1, Qt::Horizontal, tr("Gender"));
for(int row=0; row<myFace.size(); row++){
absModel
->setData
(absModel
->index
(row,
0,
QModelIndex()),
myFace.at(row).age);
absModel
->setData
(absModel
->index
(row,
1,
QModelIndex()),
myFace.at(row).gender);
}
absModel = new QStandardItemModel(8, 2, this);
absModel->setHeaderData(0, Qt::Horizontal, tr("Age"));
absModel->setHeaderData(1, Qt::Horizontal, tr("Gender"));
for(int row=0; row<myFace.size(); row++){
absModel->setData(absModel->index(row, 0, QModelIndex()),
myFace.at(row).age);
absModel->setData(absModel->index(row, 1, QModelIndex()),
myFace.at(row).gender);
}
To copy to clipboard, switch view to plain text mode
Both "age" and "gender" contain integer values. I want to show that with 2 pie charts. One of them show Ages and other one shows genders. (0:male 1:female)
ViewSetup:
agePieChart = new PieView;
genderPieChart = new PieView;
ui->splitter->addWidget(list);
ui->splitter->addWidget(table);
ui->splitter->addWidget(agePieChart);
ui->splitter->addWidget(genderPieChart);
ui->splitter->setStretchFactor(0, 0);
ui->splitter->setStretchFactor(1, 1);
table->setModel(absModel);
list->setModel(absModel);
agePieChart->setModel(absModel);
genderPieChart->setModel(absModel);
table->setSelectionModel(selectionModel);
list->setSelectionModel(selectionModel);
agePieChart->setSelectionModel(selectionModel);
genderPieChart->setSelectionModel(selectionModel);
headerView->setStretchLastSection(true);
QTableView *table = new QTableView;
QListView *list = new QListView;
agePieChart = new PieView;
genderPieChart = new PieView;
ui->splitter->addWidget(list);
ui->splitter->addWidget(table);
ui->splitter->addWidget(agePieChart);
ui->splitter->addWidget(genderPieChart);
ui->splitter->setStretchFactor(0, 0);
ui->splitter->setStretchFactor(1, 1);
table->setModel(absModel);
list->setModel(absModel);
agePieChart->setModel(absModel);
genderPieChart->setModel(absModel);
QItemSelectionModel *selectionModel = new QItemSelectionModel(absModel);
table->setSelectionModel(selectionModel);
list->setSelectionModel(selectionModel);
agePieChart->setSelectionModel(selectionModel);
genderPieChart->setSelectionModel(selectionModel);
QHeaderView *headerView = table->horizontalHeader();
headerView->setStretchLastSection(true);
To copy to clipboard, switch view to plain text mode
That code shows ListView and TableView in splitter but Charts are blank page.
Bookmarks