PDA

View Full Version : Alpha color and irregular form widget



sshd
27th February 2008, 22:46
Hi, I need to write a program similar to XTeddy, portable, I make the image to be showed and I can move it with the mouse, but it appear in a rectancle that ignore the alpha color.

Some idea of how to set the region of the widget only to the non alpha zone of the image?

Thanks

PD: sorry for my bad english

wysota
27th February 2008, 23:06
Take a look at QWidget::setMask.

sshd
28th February 2008, 19:00
I have a problem again, with the function


void CarmenTiger::paintEvent(QPaintEvent *) {
QPainter painter(this);
QPointF point;
const QImage image = QImage("tiger.png");

painter.setBackgroundMode(Qt::TransparentMode);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawImage(point, image);
} // paintEvent

the program draw the image over a rectangle and using the function


void CarmenTiger::paintEvent(QPaintEvent *) {
QLabel topLevelLabel;
QPixmap pixmap(":/tiger.png");

topLevelLabel.setPixmap(pixmap);
topLevelLabel.setMask(pixmap.mask());
} // paintEvent

the program draw only the rectangle.

Any idea of what is wrong?

jpn
28th February 2008, 19:57
You don't want to

instantiate a QLabel object (you create a label, set a pixmap, and the object is immediately destructed after paintEvent() reaches its end)
apply the mask (which is an expensive operation especially if the mask is complex)

during every paint event.

sshd
29th February 2008, 22:32
OK, I understand the problem, but I have no idea of how fix it, what I have to modify, something in the main.cpp, the constructor, the paintEvent or I have to write another function?