addPixmap won't work. Create a new icon which is a composition of both these icons and replace one icon with the other when you need it.
addPixmap won't work. Create a new icon which is a composition of both these icons and replace one icon with the other when you need it.
There's no generic plain-Qt way to achieve that... Still you can do it quite easily because QPixmap is a QPaintDevice... Hence you can do something like this (I ignored size and position stuff here but you'll have to play with them...) :
Qt Code:
p.drawPixmap(layer1); p.drawPixmap(layer2);To copy to clipboard, switch view to plain text mode
Current Qt projects : QCodeEdit, RotiDeCode
weepdoo (11th June 2007)
Hye everybody !
I can now compose icon, but, I stell have a problem: the background color.
I used the "setBackground" and "setBrush" method, but it do not seems to work as I wish.
I always have a black background (and my image are in png with alpha).
One more time: I'm developing in Python with PyQt :P
Here is the display of the pixmap alone (without painting):
image_without_composition.jpg
The code for this:
Qt Code:
import sys from PyQt4 import QtGui from PyQt4 import QtCore if __name__ == "__main__": label.setPixmap(i1) #Just display the pixmap label.show() sys.exit(app.exec_())To copy to clipboard, switch view to plain text mode
The same picture, with painting:
image_composition_alone.jpg
The code for this is:
Qt Code:
import sys from PyQt4 import QtGui, QtCore if __name__ == "__main__": i1.toImage(), painter.end() label.setPixmap(result) # <= display the result painted label.show() sys.exit(app.exec_())To copy to clipboard, switch view to plain text mode
And last (but not least), with the same code, but I load one more pixmap, I've got this:
image_composition_with_pixmap.jpg
The code is:
Qt Code:
import sys from PyQt4 import QtGui, QtCore if __name__ == "__main__": i1.toImage(), painter.end() label.setPixmap(result) label.show() sys.exit(app.exec_())To copy to clipboard, switch view to plain text mode
Why my background is not transparent ? Am I steal wrong anywhere ?
Moreover, why loading a new pixmap modify my painter ? Is it a bug in PyQt ?
Make sure the pixmap has an alpha channel. It might be easier for you to operate on QImages.
Qt Code:
pt.fill(Qt::transparent); // this might not be required pt.drawImage(...); pt.drawImage(...);To copy to clipboard, switch view to plain text mode
Here it is:
image_with_alpha.jpg
The code for this is:
Qt Code:
import sys from PyQt4 import QtGui, QtCore if __name__ == "__main__": alpha.fill(QtCore.Qt.transparent) alpha, i1.toImage(), i2.toImage(), painter.end() label.setPixmap(result) label.show() sys.exit(app.exec_())To copy to clipboard, switch view to plain text mode
Why does it do not work ???
I tried this:
Qt Code:
[...] alpha.fill(QtCore.Qt.transparent) painter.setBrush(brush) alpha, i1.toImage(), [...]To copy to clipboard, switch view to plain text mode
But it do not work... any other idea ?
I've played a bit with a very small code sample and here's what I come to so far :
Qt Code:
layer2("locked.png"), compose(layer1.size()); compose.fill(Qt::transparent); QPixmap alphacopy = layer2; alphacopy.setMask(layer2.mask()); p.drawPixmap( 0, 0, layer1); p.drawPixmap( layer1.width() - layer2.width(), layer1.height() - layer2.height(), alphacopy);To copy to clipboard, switch view to plain text mode
Note : I'm not familiar with Python so I preferred posting my C++ code and let you (or someone else) port it to Python. I should not be hard anyway...
Note bis : the tv.png comes from crystalsvg (64x64) and the locked.png I use is a 22x22, renamed, encrypted.png from crystalsvg.
Current Qt projects : QCodeEdit, RotiDeCode
weepdoo (11th June 2007)
Here is how I "translate" it to python:
Qt Code:
import sys from PyQt4 import QtGui, QtCore if __name__ == "__main__": result.fill(QtCore.Qt.transparent) alpha.setMask(i2.mask()) i1, alpha, painter.end() label.setPixmap(result) label.show() sys.exit(app.exec_())To copy to clipboard, switch view to plain text mode
Thank to everyone who help me![]()
Bookmarks