Unsolved I am not able to see any image with following code
-
Hi All
I have following code ,- class myModel: public QAbstractItemModel {
}
2 ) QtreeView is using this model
QVariant myModel::data() {
case Qt::DecorationRole:
if (index.column() == 0) {
QPixmap pixmap(10,10);
/* icon for transparent color*/
pixmap.fill(QColor(0,0,0,0));
QIcon icon(pixmap);
return icon;
}
}If my QtreeView has white background , I cannot see anything . Could you let me know why I cannot see anything ., I have to have transparent color image box on white background .What to do ?
- class myModel: public QAbstractItemModel {
-
@Qt-Enthusiast said in I am not able to see any image with following code:
If my QtreeView has white background , I cannot see anything
what does that mean? What are you expecting?
You fill it transparent on purpose :) -
I wanted to see some box with a boundary and white background like a transparent box
-
@Qt-Enthusiast
then you need to draw a border inside the transparent pixmap? -
can u please code ?
-
const int QSize iconSize(10,10); QPixmap pixmap(iconSize); pixmap.fill(Qt::transparent); QPen pen(Qt::red, 1.0); QPainter p(&pixmap); p.setBrush( Qt::NoBrush ); p.setPen( pen ); const int correctionTopLeft = qFloor( pen.width()/2.0 ); const int correctionBottomRight = -qCeil( pen.width()/2.0 ); p.drawRect( QRect(QPoint(0,0),iconSize).adjusted(correctionTopLeft,correctionTopLeft,correctionBottomRight,correctionBottomRight) ); p.end(); ...
But i suggest instead of doing the painting every time the decoration role is requested you should use a PNG file instead or at least create the Ppxmap only once and cache/re-use it when needed.