#include <QtGui>
{
public:
protected:
{
// highlight the "item" which should be spanned
painter
->setBrush
(QColor(200,
200,
200,
50));
if(index.child(0,0).isValid())
painter->drawRect(option.rect);
}
};
int main(int argc, char *argv[])
{
for (int a = 0; a < 2; ++a) {
for (int b = 0; b < 2; ++b) {
for (int c = 0; c < 2; ++c) {
for (int d = 0; d < 4; ++d) {
itemB->setChild(c,d,itemC);
}
}
itemA->setChild(b,0,itemB);
}
model.setItem(a, itemA);
}
tree.setModel(&model);
tree.setItemDelegate(new Delegate(&a));
// this I want to avoid because normally the displayed data is much more...
tree.setFirstColumnSpanned(0,model.index(-1,0),true);
tree.setFirstColumnSpanned(1,model.index(-1,0),true);
tree.setFirstColumnSpanned(0,model.index(0,0),true);
tree.setFirstColumnSpanned(1,model.index(0,0),true);
tree.setFirstColumnSpanned(0,model.index(1,0),true);
tree.setFirstColumnSpanned(1,model.index(1,0),true);
tree.show();
tree.expandAll();
return a.exec();
}
#include <QtGui>
class Delegate : public QItemDelegate
{
public:
Delegate(QObject *parent = 0);
protected:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QItemDelegate::paint(painter, option, index);
// highlight the "item" which should be spanned
painter->setBrush(QColor(200,200,200,50));
if(index.child(0,0).isValid())
painter->drawRect(option.rect);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStandardItemModel model(2, 2);
for (int a = 0; a < 2; ++a) {
QStandardItem *itemA = new QStandardItem(QString("A: %0").arg(a));
for (int b = 0; b < 2; ++b) {
QStandardItem *itemB = new QStandardItem(QString("A: %0; B: %1").arg(a).arg(b));
for (int c = 0; c < 2; ++c) {
for (int d = 0; d < 4; ++d) {
QStandardItem *itemC = new QStandardItem(QString("(%0;%1) C: %2/%3").arg(a).arg(b).arg(c).arg(d));
itemB->setChild(c,d,itemC);
}
}
itemA->setChild(b,0,itemB);
}
model.setItem(a, itemA);
}
QTreeView tree;
tree.setModel(&model);
tree.setItemDelegate(new Delegate(&a));
// this I want to avoid because normally the displayed data is much more...
tree.setFirstColumnSpanned(0,model.index(-1,0),true);
tree.setFirstColumnSpanned(1,model.index(-1,0),true);
tree.setFirstColumnSpanned(0,model.index(0,0),true);
tree.setFirstColumnSpanned(1,model.index(0,0),true);
tree.setFirstColumnSpanned(0,model.index(1,0),true);
tree.setFirstColumnSpanned(1,model.index(1,0),true);
tree.show();
tree.expandAll();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks