Hello all again!
I am stucked and need little help. I have QTableView and Costum Delegate for tableView's second column.
I think best way to express my problem is to show screenshots and source code:
mainwindow.cpp
Code:
#include "mainwindow.h" #include "ui_mainwindow.h" #include "cdelegate.h" ui(new Ui::MainWindow) { ui->setupUi(this); for(int r = 0; r < 10; ++r){ model->setItem(r,0,item); } ui->tableView->setModel(model); CDelegate *cdelegate = new CDelegate; ui->tableView->setItemDelegateForColumn(1,cdelegate); } MainWindow::~MainWindow() { delete ui; }
cdelegate.h
Code:
#ifndef CDELEGATE_H #define CDELEGATE_H #include <QAbstractItemDelegate> { public: CDelegate(); //I think this method would help to my problem }; #endif // CDELEGATE_H
and cdelegate.cpp
Code:
#include "cdelegate.h" #include <QPainter> #include <QTableView> CDelegate::CDelegate() { } { } void CDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if(index.row()%2 == 0){ painter->fillRect(option.rect,painter->brush()); } } void CDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { //... }
So,result is this:
Attachment 10070
This is a problem:
I achieved what I wanted BUT the text: "Qt is cool" isn't appeared in the second column,for every row.
I tried many solution but without any result.
Have any idea? :)

