QtitanDataGridModel-view DataGrid component with rich functionality for Qt.C++ and PySideQtitanRibbonReplicates Microsoft RibbonUI interface for Qt.C++ and PySideQtitanNavigationDesignUIReplicates Microsoft Navigation Design interface for Qt.C++ and PySideQtitanChartCharts and Diagrams component for Qt.C++ and PySideQtitanDockingDockable Panels and Tool Bars for Qt.C++ and PySideQtitanFastInfosetXML Compressed format FastInfoset implementation for Qt.C++ and PySideRoadmap Development 2023
FireDataGridPowerful, modern, fast, DB-Aware Grid for Delphi-FiremonkeyFireDockingDelphi IDE/Visual Studio implementation of dock panels for Delphi-Firemonkey
// "this" is a QWidget
auto layout = new QHBoxLayout(this);
auto grid = new Qtitan::Grid(this);
grid->setViewType(Qtitan::Grid::TableView);
auto view = grid->view<Qtitan::GridTableView>();
view->options().setColumnAutoWidth(true);
view->options().setRowAutoHeight(true);
view->options().setNewRowPlace(Qtitan::NewRowTop);
view->options().setGridLineWidth(1);
// Do I need to set a model?
view->setModel(new QStandardItemModel);
// This doesn't appear to add a column and is returning a nullptr
auto column = view->addColumn("test", "test");
layout->addWidget(grid);
layout->setContentsMargins(0, 0, 0, 0);
I'm attempting to learn how to use QTitanDataGrid but I am unable to figure out how to simply add columns or rows. None of the demos appear to show how either.
I want to make a simple table with some simple columns/rows.
QtitanGRid is build in native QT, that means that you have to first understand how Qt is thought. The grid is an implentation of the view tier of the well known Model View Controller (aka MVC) paradigm. Have a look at
qt-project.org/doc/qt-4.8/model-view-programming.html
.
If you want to add a column, the best practice to do so it's to add a column to the model that the grid is showing.
Every demo included in qtitangrid has the same concept: build a model, populate it, build a grid and attach it as a view of the model.
For example (taken from drang and drop demo):
m_grid1 = new Qtitan::Grid();
m_grid1->setViewType(Qtitan::Grid::TableView);
Qtitan::GridTableView* view1 = m_grid1->view<Qtitan::GridTableView>();
// the model! add your columns here!!!
QStandardItemModel* model1 = new QStandardItemModel(4, 4);
for (int row = 0; row < 4; ++row)
{
for (int column = 0; column < 4; ++column)
{
QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
model1->setItem(row, column, item);
}
}
view1->setModel(model1);
Last edit: 10 years 4 months ago by corrado valeri.
Thank you for the help so far. That indeed works and generates a 4x4 table.
My next problem is the follow:
auto grid = new Grid();
grid->setViewType(Grid::TableView);
auto view = grid->view<GridTableView>();
auto model = new QStandardItemModel();
view->setModel(model);
QStringList titles;
titles.push_back("Col1");
titles.push_back("Col2");
titles.push_back("Col3");
// etc...
model->setColumnCount(titles.size());
model->setHorizontalHeaderLabels(titles);
The above code yields a table of 0 columns with no Header Labels. I'm attempting a dynamic table which loads X columns from a config file. I need to be able to add any number of columns from a given config file.
Any ideas why this results in 0 columns?
Edit:
model->setColumnCount(10);
view->setModel(model);
It appears I have to set the column count before I set the model???