adutzu89
19th March 2014, 11:27
I am having issues setting font weight for a column inside QTableView's model.
I found that I can use QFont for it, but I cannot find a way to set only the font weight, I want the text bolded for some cells.
I tried it like this:
QVariant ModelLIes::data(const QModelIndex &index, int role) const{
QVariant value = QSqlQueryModel::data(index, role);
if(index.column() == 5){
if(role == Qt::FontRole){
int valStare=QSqlQueryModel::data(index, Qt::DisplayRole).toInt(); // to check which cells to modify in the column
QFontInfo info(QSqlQueryModel::data(index, Qt::DisplayRole).toString());
int marime=info.pointSize(); //tried also pixelSize();
QString fam=info.family();
if(valStare==1)
return QFont(fam, marime,QFont::Bold);
}
}
return value;
}
But the font is different from the rest of my tableview.(Is it setting the font size and family to what I am using on my OS?)
Any suggestions?
I found that I can use QFont for it, but I cannot find a way to set only the font weight, I want the text bolded for some cells.
I tried it like this:
QVariant ModelLIes::data(const QModelIndex &index, int role) const{
QVariant value = QSqlQueryModel::data(index, role);
if(index.column() == 5){
if(role == Qt::FontRole){
int valStare=QSqlQueryModel::data(index, Qt::DisplayRole).toInt(); // to check which cells to modify in the column
QFontInfo info(QSqlQueryModel::data(index, Qt::DisplayRole).toString());
int marime=info.pointSize(); //tried also pixelSize();
QString fam=info.family();
if(valStare==1)
return QFont(fam, marime,QFont::Bold);
}
}
return value;
}
But the font is different from the rest of my tableview.(Is it setting the font size and family to what I am using on my OS?)
Any suggestions?