Results 1 to 5 of 5

Thread: PyQt5 QPixmap

  1. #1
    Join Date
    Feb 2015
    Posts
    27
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default PyQt5 QPixmap

    I've just converted a small app from Python2/Qt4 to Python3/Qt5 without much difficulty. It displays .jpg images, but it no longer displays .tif images.
    Qt Code:
    1. #! /usr/bin/python3
    2.  
    3. import sys
    4. from PyQt5 import QtCore, QtGui, QtWidgets
    5. from test_ui import Ui_MainWindow
    6.  
    7. class MyWindowClass(QtWidgets.QMainWindow):
    8. def __init__(self, parent=None):
    9. QtWidgets.QMainWindow.__init__(self, parent)
    10. self.ui = Ui_MainWindow()
    11. self.ui.setupUi(self)
    12.  
    13. self.ui.buttonProcessOne.clicked.connect(self.pushButtonClicked)
    14.  
    15. def pushButtonClicked(self):
    16. myPixmap = QtGui.QPixmap('image1.tif')
    17. self.ui.label.setScaledContents(True)
    18. self.ui.label.setPixmap(myPixmap)
    19.  
    20.  
    21. if __name__ == "__main__":
    22. app = QtWidgets.QApplication(sys.argv)
    23. mywindow = MyWindowClass()
    24. mywindow.show()
    25. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    I have tried QtWidgets.QPixmap instead of QtGui.
    Last edited by ChrisOfBristol; 4th April 2015 at 13:03.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQt5 QPixmap

    Maybe plugin for tif images did not get built or was not loaded.

    Check QtGui.QImageReader.supportedImageFormats()

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    ChrisOfBristol (4th April 2015)

  4. #3
    Join Date
    Feb 2015
    Posts
    27
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQt5 QPixmap

    I'd tried something like that and it didn't work because I'd got something wrong. This one works, with this result:
    [PyQt5.QtCore.QByteArray(b'bmp'), PyQt5.QtCore.QByteArray(b'gif'), PyQt5.QtCore.QByteArray(b'ico'), PyQt5.QtCore.QByteArray(b'jpeg'), PyQt5.QtCore.QByteArray(b'jpg'), PyQt5.QtCore.QByteArray(b'pbm'), PyQt5.QtCore.QByteArray(b'pgm'), PyQt5.QtCore.QByteArray(b'png'), PyQt5.QtCore.QByteArray(b'ppm'), PyQt5.QtCore.QByteArray(b'svg'), PyQt5.QtCore.QByteArray(b'svgz'), PyQt5.QtCore.QByteArray(b'xbm'), PyQt5.QtCore.QByteArray(b'xpm')]
    Any idea what I need to do to load the right plugin?

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQt5 QPixmap

    You don't have to do anything in particular, it looks like the plugin for tif is missing.

    Comparing the documentation of QImageReader of Qt4 and Qt5 it seems that TIFF is no longer supported by default.

    No idea why or if the plugin was moved to a addon package of sorts.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    ChrisOfBristol (4th April 2015)

  7. #5
    Join Date
    Feb 2015
    Posts
    27
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQt5 QPixmap

    I have found a package in the software manager called qt5-image-formats-plugins. Installing this fixes the problem.
    Last edited by ChrisOfBristol; 4th April 2015 at 22:02.

Similar Threads

  1. QPixmap
    By dragon in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2010, 19:19
  2. Replies: 4
    Last Post: 28th August 2008, 13:13
  3. Replies: 1
    Last Post: 21st August 2008, 07:44
  4. Replies: 5
    Last Post: 9th April 2007, 14:26
  5. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 17:11

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.