nategoofs

20th August 2007, 05:09

Im using a QAbstractTableModel with a QTableView and I would like to change a few things graphically.

1. I know how to make one specific column editable. However, when I select a row, the entire row does not highlight, only the editable column on that row is highlighted. How do I go about getting the entire row highlighted, but leaving the one column eligible for editing.

Here is my flags function:

Qt::ItemFlags WTrackTableModel::flags(const QModelIndex &index) const

{

if (!index.isValid())

return Qt::ItemIsEnabled;

switch(index.column())

{

case 7: return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;

}

return Qt::ItemIsEnabled;

}

2. I set my row colors according to the color taken from an xml file like so if row colors are present:

void WTrackTableView::setup(QDomNode node)

{

// Position

if (!WWidget::selectNode(node, "Pos").isNull())

{

QString pos = WWidget::selectNodeQString(node, "Pos");

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())

{

QString size = WWidget::selectNodeQString(node, "Size");

int x = size.left(size.find(",")).toInt();

int y = size.mid(size.find(",")+1).toInt();

setFixedSize(x,y);

}

// Foreground color

QColor fgc(0,0,0);

if (!WWidget::selectNode(node, "FgColor").isNull())

{

fgc.setNamedColor(WWidget::selectNodeQString(node, "FgColor"));

}

m_pTable->setForegroundColor(fgc);

// 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);

QPalette Rowpalette = palette();

Rowpalette.setColor(QPalette::Base, r1);

Rowpalette.setColor(QPalette::AlternateBase, r2);

setPalette(Rowpalette);

}

/*

// 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"));

}

*/

}

in the QTableView on lines 28-41. Now what I would like to do is use the colors found in the BPM if statement on items in one single column. Say I have a function [bool bpmConfirm()] that returns true if the BPM is confirmed, I would then like to use r2, and r1 is the BPM is not confirmed. How would I go about doing this?

just for reference, here is what my data function looks like in my model:

QVariant WTrackTableModel :: data(const QModelIndex &index, int role) const

{

TrackInfoObject *m_pTrackInfo = m_pTrackPlaylist->getTrackAt(index.row());

if (!index.isValid())

return QVariant();

if (index.row() >= m_pTrackPlaylist->getSongNum())

return QVariant();

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

return QVariant();

}

Thanks!

Nate

1. I know how to make one specific column editable. However, when I select a row, the entire row does not highlight, only the editable column on that row is highlighted. How do I go about getting the entire row highlighted, but leaving the one column eligible for editing.

Here is my flags function:

Qt::ItemFlags WTrackTableModel::flags(const QModelIndex &index) const

{

if (!index.isValid())

return Qt::ItemIsEnabled;

switch(index.column())

{

case 7: return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;

}

return Qt::ItemIsEnabled;

}

2. I set my row colors according to the color taken from an xml file like so if row colors are present:

void WTrackTableView::setup(QDomNode node)

{

// Position

if (!WWidget::selectNode(node, "Pos").isNull())

{

QString pos = WWidget::selectNodeQString(node, "Pos");

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())

{

QString size = WWidget::selectNodeQString(node, "Size");

int x = size.left(size.find(",")).toInt();

int y = size.mid(size.find(",")+1).toInt();

setFixedSize(x,y);

}

// Foreground color

QColor fgc(0,0,0);

if (!WWidget::selectNode(node, "FgColor").isNull())

{

fgc.setNamedColor(WWidget::selectNodeQString(node, "FgColor"));

}

m_pTable->setForegroundColor(fgc);

// 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);

QPalette Rowpalette = palette();

Rowpalette.setColor(QPalette::Base, r1);

Rowpalette.setColor(QPalette::AlternateBase, r2);

setPalette(Rowpalette);

}

/*

// 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"));

}

*/

}

in the QTableView on lines 28-41. Now what I would like to do is use the colors found in the BPM if statement on items in one single column. Say I have a function [bool bpmConfirm()] that returns true if the BPM is confirmed, I would then like to use r2, and r1 is the BPM is not confirmed. How would I go about doing this?

just for reference, here is what my data function looks like in my model:

QVariant WTrackTableModel :: data(const QModelIndex &index, int role) const

{

TrackInfoObject *m_pTrackInfo = m_pTrackPlaylist->getTrackAt(index.row());

if (!index.isValid())

return QVariant();

if (index.row() >= m_pTrackPlaylist->getSongNum())

return QVariant();

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

return QVariant();

}

Thanks!

Nate