# HG changeset patch # User John Kern # Date 1284087814 25200 # Node ID c6e75ec74fc8170bf7a43813a16b0b459d368e3d # Parent 702dd26c0f4d0aa8c43c20b150754357484a64c3 add colors via delegate diff -r 702dd26c0f4d -r c6e75ec74fc8 ListElements/ModelViewList/listElements.pro --- 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 \ diff -r 702dd26c0f4d -r c6e75ec74fc8 ListElements/ModelViewList/mainwindow.cpp --- 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; diff -r 702dd26c0f4d -r c6e75ec74fc8 ListElements/ModelViewList/zodiacdelegate.cpp --- 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()); + // 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()); + // 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(); } diff -r 702dd26c0f4d -r c6e75ec74fc8 ListElements/ModelViewList/zodiacmodel.cpp --- 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; }