Hi Everyone!
I've just picked up Qt as I do a lot of work in Autodesk Maya, I'm using the 'PySide' python implementation though answers with the PyQt4 implementation or C++ is fine as well, I'll just try and translate :P
So I've got an icon, which is a 64x64 pixel PNG image, and I've got a custom widget that subclasses QWidget. In the paintEvent, I want to paint this image to the widget.
From looking up examples I thought the bare minimum I needed to do to make it display was:
import PySide.QtGui as QtGui
import PySide.QtCore as QtCore
def __init__(self):
super(CustomWidget, self).__init__()
self._pixmap
= QtGui.
QPixmap("C:/.../icons/arrow_down.png")
def paintEvent(self, event):
painter.drawPixmap(event.rect(), self._pixmap)
import PySide.QtGui as QtGui
import PySide.QtCore as QtCore
class CustomWidget(QtGui.QWidget):
def __init__(self):
super(CustomWidget, self).__init__()
self._pixmap = QtGui.QPixmap("C:/.../icons/arrow_down.png")
def paintEvent(self, event):
painter = qg.QPainter(self)
painter.drawPixmap(event.rect(), self._pixmap)
To copy to clipboard, switch view to plain text mode
This widget is just being added to a layout however no image is displayed. Everything else I've tried (setting a custom rect object etc) hasn't worked and I have no idea what to do.. any help is greatly appreciated.
Kinds Regards,
Kaine
EDIT:
I just saved my image as a jpeg, and with that same code above, it displays.. however I need to be able to make use of the PNGs alpha channel. My icon is a small arrow, and I want to display JUST the arrow, not any colour around it.
Bookmarks