2
I wonder, how do I add in a tableView
to the property of background
and icone
? I can already add the Background
now is missing the icon.
Code:
class tableView : public QSqlTableModel
{
Q_OBJECT
public:
tableView(QObject * parent = 0, QSqlDatabase db = QSqlDatabase())
: QSqlTableModel(parent,db) {;}
QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
{
if(role==Qt::BackgroundColorRole) {
const QVariant value(data(index,Qt::DisplayRole));
if(value.toString()=="Sim"){
return QVariant(QColor("#d0ffe3")); //<<background
}else if (value.toString()=="Não"){
return QVariant(QColor("#ffe3d0")); //<<background
}else if (value.toString()=="Neutro"){
return QVariant(QColor("#fffad0")); //<<background
}
}
return QSqlTableModel::data(index,role);
}
};
Returns everything in Qvariant? how would this code return all Qpixmap,qicon,qcolor objects?
– Hy-brazil
I edited to improve the example
– Bacco
OK, thank you very much.
– Hy-brazil
@user628298 the function is called several flows. Each time with a different role.
– Guilherme Bernal
Now it worked, but in the second
if
have to tradeQt::BackgroundColorRole
forQt::DisplayRole
. Thank you– Hy-brazil
@user628298 is actually Qt::Decorationrole, I had edited wrong
– Bacco
@Bacco You know how to increase icon size?
– Hy-brazil
@user628298 Increase to look different from the original image?
– Bacco
@Bacco Increases the size of the Qicon in the view. The icon has 32x32, but in the display of the tableView. It appears super small +- 10x10.
– Hy-brazil
@Bacco got it. I was looking in the class
QIcon
instead of the classQtableView
.ui->tableView->setIconSize(QSize(32, 32));
– Hy-brazil