--- a/ListElements/ModelViewList/listElements.pro Thu Sep 09 14:29:26 2010 -0700
+++ b/ListElements/ModelViewList/listElements.pro Thu Sep 09 20:03:34 2010 -0700
@@ -17,9 +17,6 @@
zodiacdelegate.cpp \
PLLayout.cpp
-
-# DEFINES = USE_DELEGATE
-
HEADERS += mainwindow.h \
zodiacsign.h \
zodiacmodel.h \
--- a/ListElements/ModelViewList/mainwindow.cpp Thu Sep 09 14:29:26 2010 -0700
+++ b/ListElements/ModelViewList/mainwindow.cpp Thu Sep 09 20:03:34 2010 -0700
@@ -26,10 +26,8 @@
// define the model
ZodiacModel *zModel = new ZodiacModel(this);
listView->setModel(zModel);
-#ifdef USE_DELEGATE
ZodiacDelegate *delegate = new ZodiacDelegate(this);
listView->setItemDelegate(delegate);
-#endif
// create landscape layout
layoutLandscape = new QHBoxLayout;
--- a/ListElements/ModelViewList/zodiacdelegate.cpp Thu Sep 09 14:29:26 2010 -0700
+++ b/ListElements/ModelViewList/zodiacdelegate.cpp Thu Sep 09 20:03:34 2010 -0700
@@ -8,14 +8,15 @@
const QModelIndex &index) const
{
painter->save();
- painter->setPen(Qt::red);
- painter->setBrush(Qt::yellow);
painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
}
+ // use color assocaited with Zodiac for background.
+ painter->fillRect(option.rect,index.model()->data(index,Qt::BackgroundRole).value<QBrush>());
+
// draw the svg image.
int xOffset = 10;
int yOffset = 5;
@@ -26,16 +27,15 @@
QSvgRenderer renderer(svgFile);
renderer.render(painter,imgRect);
- // write the name
+ // now we will draw the name
+ // set the pen
+ painter->setPen(index.model()->data(index,Qt::TextColorRole).value<QColor>());
+ // determine geometry
int xOffsetText = 55;
QRect rect(option.rect.x()+xOffsetText,option.rect.y(),option.rect.width(), option.rect.height());
+ // write the name
painter->drawText(rect,Qt::AlignVCenter,
index.model()->data(index,Qt::DisplayRole).toString());
- // just for debugging
- QPoint point(option.rect.x()+xOffsetText,option.rect.y());
- painter->drawLine(point+QPoint(-5,0),point+QPoint(5,0));
- painter->drawLine(point+QPoint(0,-5),point+QPoint(0,5));
-
painter->restore();
}
--- a/ListElements/ModelViewList/zodiacmodel.cpp Thu Sep 09 14:29:26 2010 -0700
+++ b/ListElements/ModelViewList/zodiacmodel.cpp Thu Sep 09 20:03:34 2010 -0700
@@ -111,6 +111,8 @@
{
// white text on a white or yellow background doesn't work. Let's change it.
rc = QVariant(QColor("silver"));
+ } else {
+ rc = QVariant (QColor(Qt::white));
}
break;
}