PDA

View Full Version : Star Delegate Example



graciano
7th February 2010, 20:05
Hello,
If using a model/view based on QSqlRelationalTableModel/QTableView, can i use this delegate to handle one column of the view that holds the appropriate data(int in the range of 1 to 5)?
Showld't it be as simple as...


...
view->setItemDelegateForColumn(3, new StarDelegate);
...


Thanks

aamer4yu
8th February 2010, 05:47
Reading from the docs ,,yes.
It would have cost you less time testing urself ;)

graciano
9th February 2010, 09:45
I had done it before i asked;)
I get no error and the star delegate never shows up!
Must be doing something "stupid"... i will take a better look.

aamer4yu
9th February 2010, 09:56
check the trigger modes if you have set on the view if any

graciano
9th February 2010, 10:29
Thanks ... i wĩll ... as soon as i get home.

graciano
9th February 2010, 16:55
I tried mixing the "spin box" and the "star" delegate examples like this:


#include <QApplication>
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QStandardItemModel>
#include <QTableView>

#include "delegate.h"
#include "stardelegate.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel model(4, 2);
QTableView tableView;
tableView.setModel(&model);
SpinBoxDelegate delegateForColumn0;
StarDelegate delegateForColumn1;
tableView.setItemDelegateForColumn(0, &delegateForColumn0);
tableView.setItemDelegateForColumn(1, &delegateForColumn1);
tableView.horizontalHeader()->setStretchLastSection(true);
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant(row+1));
}
}
tableView.setWindowTitle(QObject::tr("Spin Box/Star Delegates"));
tableView.show();
return app.exec();
}


No stars yet?!