Transparent color in Qt
-
Hi
We tried to create a transparent image , but it is not giving me proper results .QPixmap pix(500,500);
QPainter *paint = new QPainter(&pix);
paint->setPen(QColor(255,34,255,255));
paint->setBrush(QColor(255,34,255,50));
paint->drawRect(15,15,100,100);
delete paint;Can some one guide me for that
-
so what do u get?
-
I am some black image . I want a trasparent color image with a boundary colored
-
I tried this also
QPixmap cellPixmap(QSize(10,10));
QPainter *paint = new QPainter(&cellPixmap);
paint->setPen(Qt::transparent);
paint->setBrush(Qt::transparent);
paint->drawRect(10,10,10,10);
delete paint;
QIcon icon(cellPixmap);
return icon;
I am still getting black image .What is purpose of setPen and setBrush
-
hi
can you try
paint->setPen(QColor(255,0,0));
paint->setBrush(QColor(255,0,0));
and tell me if its red.
Else something else is wrong.also u say
QPixmap cellPixmap(QSize(10,10));
paint->drawRect(10,10,10,10);which means u draw OUTSIDE your image.
the image is only 10x10.
and u tell rect to start at 10,10 -
With this code
QPixmap cellPixmap(QSize(10,10));
QPainter *paint = new QPainter(&cellPixmap);
paint->setPen(QColor(255,0,0));
paint->setBrush(QColor(255,0,0));
paint->drawRect(0,0,10,10);
delete paint;
QIcon icon(cellPixmap);I cannot see any thing . Could you correct my code
-
it looks fine except no need to new it
QPainter paint(&cellPixmap);
paint.setPen(QColor(255,0,0));
paint.setBrush(QColor(255,0,0));
paint.drawRect(0,0,10,10); -
void MainWindow::on_pushButton_3_released() { QPixmap pixmap(100,100); pixmap.fill(QColor("transparent")); QPainter paint(&pixmap); paint.setPen(QColor(255,0,0)); paint.setBrush(QColor(255,0,0)); paint.drawRect(0,0,10,10); ui->label->setPixmap(pixmap); }
This does produce red rect for me.
(testing with QLabel) -
but how to get transparent color with a boundary without any solid fill . Let me know
[link text](link url http://doc.qt.io/qt-4.8/qpainter.html#drawRect-3 , image with square with no fill just the boundary
-
@Qt-Enthusiast
paint.setBrush(QColor("transparent"));gives me