Im using a reimplemented QAbstractTableModel and a QTableView. What Im doing is getting information about how the model/view should look from an xml file (background color, foreground color etc.)
This is from my view...
Code:
{ // Position if (!WWidget::selectNode(node, "Pos").isNull()) { int x = pos.left(pos.find(",")).toInt(); int y = pos.mid(pos.find(",")+1).toInt(); move(x,y); } // Size if (!WWidget::selectNode(node, "Size").isNull()) { int x = size.left(size.find(",")).toInt(); int y = size.mid(size.find(",")+1).toInt(); setFixedSize(x,y); } // Background color if (!WWidget::selectNode(node, "BgColor").isNull()) { bgc.setNamedColor(WWidget::selectNodeQString(node, "BgColor")); } m_pTable->setBackgroundColor(bgc); // Foreground color if (!WWidget::selectNode(node, "FgColor").isNull()) { fgc.setNamedColor(WWidget::selectNodeQString(node, "FgColor")); } m_pTable->setForegroundColor(bgc); /* // Row colors if (!WWidget::selectNode(node, "BgColorRowEven").isNull()) { QColor r1; r1.setNamedColor(WWidget::selectNodeQString(node, "BgColorRowEven")); QColor r2; r2.setNamedColor(WWidget::selectNodeQString(node, "BgColorRowUneven")); setAlternatingRowColors ( true ); m_pTable->setRowColor(r1, r2); } // BPM confidence colors if (!WWidget::selectNode(node, "BgColorBpmNoConfirm").isNull()) { QColor c1; c1.setNamedColor(WWidget::selectNodeQString(node, "BgColorBpmNoConfirm")); QColor c2; c2.setNamedColor(WWidget::selectNodeQString(node, "BgColorBpmConfirm")); WTrackTableItem::setBpmBgColors(WSkinColor::getCorrectColor(c1), WSkinColor::getCorrectColor(c2)); } */ }
Here are the functions in the model:
Code:
{ backgroundColor = bgColor; } { foregroundColor = fgColor; } { rowEvenColor = evenColor; rowUnevenColor = unevenColor; } { bpmNoConfirmColor = noConfirmColor; bpmConfirmColor = confirmColor; }
And Finally, the data function:
Code:
{ TrackInfoObject *m_pTrackInfo = m_pTrackCollection->getTrack(index.row()+1); if (!index.isValid()) if (index.row() >= m_pTrackCollection->getSize()) if (role == Qt::BackgroundRole) { return backgroundColor; } if (role == Qt::ForegroundRole ) { return foregroundColor; } else if (role == Qt::DisplayRole ) { switch(index.column()) { case 0: return m_pTrackInfo->getScoreStr(); case 1: return m_pTrackInfo->getTitle(); case 2: return m_pTrackInfo->getArtist(); case 3: return m_pTrackInfo->getType(); case 4: return m_pTrackInfo->getDurationStr(); case 5: return m_pTrackInfo->getBitrateStr(); case 6: return m_pTrackInfo->getBpmStr(); case 7: return m_pTrackInfo->getComment(); } } else }
Now my problem is that the foreground color does not come out as I want it to. It compiles fine, but when I go to look at my model/view at first glance it appears to be an empty table. but when I click around, the Items in the model show up fine when they're highlighted. What could be causing this?
Also, I'm having some trouble figuring out how to set up alternating colors in my model. as you can see setAlternatingRowColors(true) is used but i dont feel that it is working. What do I need to do to these functions to get them to set the row coloring?
Thanks!