Using the Spin Box Delegate Example, I was able to create a more complex delegate system that included QDateTime, QLineEdit, and QComboBox for the columns. My class works perfectly when I use the example main.cpp from the spinbox delegate example.
I made a window in designer with a QTableView in it, and attempted to apply the the model and delegate to it as follows:
//setup interface of main window:
setupUi(this);
inventoryDelegate delegate;
tableView->setModel(&model);
tableView->setItemDelegate(&delegate);
//connect form item signals to slots that arent in the UI file here:
connect(buttonBox, SIGNAL(accepted()), this, SLOT(returnVars()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
database = db;
}
//setup interface of main window:
DialogAddInventoryMass::DialogAddInventoryMass(QWidget *parent, QSqlDatabase db) : QDialog(parent) {
setupUi(this);
QStandardItemModel model(10, 9);
inventoryDelegate delegate;
tableView->setModel(&model);
tableView->setItemDelegate(&delegate);
//connect form item signals to slots that arent in the UI file here:
connect(buttonBox, SIGNAL(accepted()), this, SLOT(returnVars()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
database = db;
}
To copy to clipboard, switch view to plain text mode
What I expected to see (as I did using the spin box example main.cpp) would be my QTableView with 10 rows, and 9 columns, and the delegate working properly.
What actually happens, is a blank QTableView, no rows/columns in it, and there are no errors (either in compilation or runtime). I also have cell borders enabled in the .ui file and console enabled.
What might the reason be that the QStandardItemModel is not applied to the QTableView in my UI?
Bookmarks