Results 1 to 10 of 10

Thread: Making Icon with more than one image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2006
    Location
    France
    Posts
    34
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Making Icon with more than one image

    Here it is:
    image_with_alpha.jpg

    The code for this is:
    Qt Code:
    1. import sys
    2. from PyQt4 import QtGui, QtCore
    3.  
    4. if __name__ == "__main__":
    5. app = QtGui.QApplication(sys.argv)
    6.  
    7. i1 = QtGui.QPixmap('qtg_aircraft.png')
    8. i2 = QtGui.QPixmap('qtg_locked.png')
    9.  
    10. alpha = QtGui.QPixmap(QtCore.QSize(24, 24))
    11. alpha.fill(QtCore.Qt.transparent)
    12.  
    13. result = QtGui.QPixmap(QtCore.QSize(24, 24))
    14.  
    15. painter = QtGui.QPainter(result)
    16.  
    17. painter.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
    18.  
    19. painter.drawPixmap(QtCore.QRect(0, 0, 24, 24),
    20. alpha,
    21. QtCore.QRect(0, 0, 24, 24))
    22.  
    23. painter.drawImage(QtCore.QRect(0, 0, 24, 24),
    24. i1.toImage(),
    25. QtCore.QRect(0, 0, 24, 24))
    26.  
    27. painter.drawImage(QtCore.QRect(0, 0, 15, 15),
    28. i2.toImage(),
    29. QtCore.QRect(0, 0, 24, 24))
    30.  
    31. painter.end()
    32.  
    33. label = QtGui.QLabel()
    34. label.setPixmap(result)
    35. label.show()
    36. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Why does it do not work ???

  2. #2
    Join Date
    Jul 2006
    Location
    France
    Posts
    34
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Making Icon with more than one image

    I tried this:
    Qt Code:
    1. [...]
    2. i1 = QtGui.QPixmap('qtg_aircraft.png')
    3. i2 = QtGui.QPixmap('qtg_locked.png')
    4.  
    5. alpha = QtGui.QPixmap(QtCore.QSize(24, 24))
    6. alpha.fill(QtCore.Qt.transparent)
    7.  
    8. result = QtGui.QPixmap(QtCore.QSize(24, 24))
    9.  
    10. painter = QtGui.QPainter(result)
    11.  
    12. brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
    13. brush.setColor(QtGui.QColor(QtCore.Qt.transparent))
    14.  
    15. painter.setBrush(brush)
    16.  
    17. painter.drawPixmap(QtCore.QRect(0, 0, 24, 24),
    18. alpha,
    19. QtCore.QRect(0, 0, 24, 24))
    20.  
    21. painter.drawImage(QtCore.QRect(0, 0, 24, 24),
    22. i1.toImage(),
    23. QtCore.QRect(0, 0, 24, 24))
    24. [...]
    To copy to clipboard, switch view to plain text mode 

    But it do not work... any other idea ?

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Making Icon with more than one image

    I've played a bit with a very small code sample and here's what I come to so far :

    Qt Code:
    1. QPixmap layer1("tv.png"),
    2. layer2("locked.png"),
    3. compose(layer1.size());
    4.  
    5. compose.fill(Qt::transparent);
    6.  
    7. QPixmap alphacopy = layer2;
    8. alphacopy.setMask(layer2.mask());
    9.  
    10. QPainter p(&compose);
    11. p.drawPixmap( 0,
    12. 0,
    13. layer1);
    14.  
    15. p.drawPixmap( layer1.width() - layer2.width(),
    16. layer1.height() - layer2.height(),
    17. 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.
    Attached Images Attached Images
    Current Qt projects : QCodeEdit, RotiDeCode

  4. The following user says thank you to fullmetalcoder for this useful post:

    weepdoo (11th June 2007)

  5. #4
    Join Date
    Jul 2006
    Location
    France
    Posts
    34
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Making Icon with more than one image

    Here is how I "translate" it to python:
    Qt Code:
    1. import sys
    2. from PyQt4 import QtGui, QtCore
    3.  
    4. if __name__ == "__main__":
    5. app = QtGui.QApplication(sys.argv)
    6.  
    7. i1 = QtGui.QPixmap('qtg_aircraft.png')
    8. i2 = QtGui.QPixmap('qtg_locked.png')
    9.  
    10. result = QtGui.QPixmap(QtCore.QSize(24, 24))
    11. result.fill(QtCore.Qt.transparent)
    12.  
    13. alpha = QtGui.QPixmap(i2)
    14. alpha.setMask(i2.mask())
    15.  
    16. painter = QtGui.QPainter(result)
    17.  
    18. painter.drawPixmap(QtCore.QRect(0, 0, 24, 24),
    19. i1,
    20. QtCore.QRect(0, 0, 24, 24))
    21.  
    22. painter.drawPixmap(QtCore.QRect(0, 0, 15, 15),
    23. alpha,
    24. QtCore.QRect(0, 0, 24, 24))
    25.  
    26. painter.end()
    27.  
    28. label = QtGui.QLabel()
    29. label.setPixmap(result)
    30. label.show()
    31. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Thank to everyone who help me

Similar Threads

  1. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 21:55
  2. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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
  •  
Qt is a trademark of The Qt Company.