Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QImage::setAlphaChannel -- obsolete or not?
QtWS25 Last Chance

QImage::setAlphaChannel -- obsolete or not?

Scheduled Pinned Locked Moved Solved General and Desktop
qimagec++obsoletealphachannel
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FeRDNYC
    wrote on 5 Dec 2020, 01:47 last edited by
    #1

    Looking at the current documentation for QImage, the method QImage::setAlphaChannel() is listed with no mention of it being obsolete/deprecated/etc, nor any admonishment against its use in new code:

    void QImage::setAlphaChannel(const QImage &alphaChannel)

    Sets the alpha channel of this image to the given alphaChannel.

    If alphaChannel is an 8 bit alpha image, the alpha values are used directly. Otherwise, alphaChannel is converted to 8 bit grayscale and the intensity of the pixel values is used.

    If the image already has an alpha channel, the existing alpha channel is multiplied with the new one. If the image doesn't have an alpha channel it will be converted to a format that does.

    The operation is similar to painting alphaChannel as an alpha image over this image using QPainter::CompositionMode_DestinationIn.

    See also hasAlphaChannel(), alphaChannel(), Image Transformations, and Image Formats.

    ...Which is weird, because even as far back in Qt 5.11 setAlphaChannel() was listed as an obsolete member for QImage.

    Use one of the composition modes in QPainter::CompositionMode instead.

    Warning: This function is expensive.

    What gives? Did setAlphaChannel() get "un-obsoleted"? Or did it just end up back in the wrong part of the docs? (Perhaps accidentally getting restored to visibility, when it was supposed to be excised entirely?)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 5 Dec 2020, 08:48 last edited by
      #2

      setAlphaChannel was un-deprecated in 5.15

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      F 1 Reply Last reply 5 Dec 2020, 09:25
      3
      • C Christian Ehrlicher
        5 Dec 2020, 08:48

        setAlphaChannel was un-deprecated in 5.15

        F Offline
        F Offline
        FeRDNYC
        wrote on 5 Dec 2020, 09:25 last edited by
        #3

        @Christian-Ehrlicher Aha! Thanks, good to know. I guess that explains this, then:

        >>> from PyQt5 import QtCore, QtGui
        >>> i = QtGui.QImage("/tmp/front3.jpg")
        >>> m = QtGui.QImage("/tmp/mask.png")
        >>> m = m.convertToFormat(QtGui.QImage.Format_Alpha8)
        >>> i.setAlphaChannel(m)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        AttributeError: 'QImage' object has no attribute 'setAlphaChannel'
        >>> QtCore.PYQT_VERSION_STR
        '5.14.2'
        >>> QtCore.QT_VERSION_STR
        '5.14.2'
        

        Ooh. Then again, maybe not. Looks like Riverbank didn't get a memo. (After installing from the latest wheels...):

        >>> from PyQt5 import QtCore, QtGui
        >>> i = QtGui.QImage("/tmp/front3.jpg")
        >>> m = QtGui.QImage("/tmp/mask.png")
        >>> m = m.convertToFormat(QtGui.QImage.Format_Alpha8)
        >>> i.setAlphaChannel(m)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        AttributeError: 'QImage' object has no attribute 'setAlphaChannel'
        >>> QtCore.QT_VERSION_STR
        '5.15.2'
        >>> QtCore.PYQT_VERSION_STR
        '5.15.2'
        

        Welp, I've got a bug report to file. Thanks for the help!

        1 Reply Last reply
        2

        1/3

        5 Dec 2020, 01:47

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved