Results 1 to 4 of 4

Thread: Painting png image to widget, nothing displays

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2016
    Posts
    3
    Qt products
    Platforms
    Windows

    Default Painting png image to widget, nothing displays

    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:

    Qt Code:
    1. import PySide.QtGui as QtGui
    2. import PySide.QtCore as QtCore
    3.  
    4. class CustomWidget(QtGui.QWidget):
    5. def __init__(self):
    6. super(CustomWidget, self).__init__()
    7.  
    8. self._pixmap = QtGui.QPixmap("C:/.../icons/arrow_down.png")
    9.  
    10. def paintEvent(self, event):
    11. painter = qg.QPainter(self)
    12. 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.
    Last edited by kainev; 13th May 2016 at 06:35. Reason: updated contents

Similar Threads

  1. Painting one Image from another Image with paint brush
    By avanindra in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2012, 12:08
  2. Replies: 1
    Last Post: 7th September 2008, 10:47
  3. Painting an image on QItemDelegates
    By sprek in forum Qt Programming
    Replies: 4
    Last Post: 12th June 2008, 00:00
  4. custom widgets painting image formats
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2007, 10:33
  5. Trouble with image painting (QPainter + QImage)
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2006, 20:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.