Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. OpacityMask doesn't work for me ... what am I missing?
Forum Updated to NodeBB v4.3 + New Features

OpacityMask doesn't work for me ... what am I missing?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.7k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cscooper
    wrote on last edited by
    #1

    I downloaded the images & used the QML code from the OpacityMask documentation page (qt-project.org/doc/qt-5/qml-qtgraphicaleffects-opacitymask.html) but it isn't doing what I expect. I though I would end up with a mostly red screen with a butterfly-shaped picture of a bug, but what I get instead is a boring square picture of a bug (on a red screen). There are no warnings in the console that would indicate the problem. Am I just mis-understanding the purpose of OpacityMask?

    Thanks,
    Chris

    @
    import QtQuick 2.2
    import QtQuick.Controls 1.2
    import QtGraphicalEffects 1.0

    Item
    {
    id: screen
    anchors.fill: parent

    Rectangle {
        anchors.fill: parent
    
        color: "red"
    
    }
    
    Item
    {
        id: hole
        anchors.fill: parent
    
        Image
        {
            id: bug
            source:"qrc:/Bug.png"
            sourceSize: Qt.size(parent.width, parent.height)
            smooth: true
            visible: false
        }
    
        Image
        {
            id: mask
            source:"qrc:/Butterfly.png"
            sourceSize: Qt.size(parent.width, parent.height)
            smooth: true
            visible: false
        }
    
        OpacityMask {
            anchors.fill: bug
            source: bug
            maskSource: mask
        }
    }
    

    }
    @

    [edit: added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Make sure the image source files are in the resources.
      QtCreator must have shown the error in the console when you run the application.

      157

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cscooper
        wrote on last edited by
        #3

        I figured out the problem, I downloaded the Butterfly.png from the OpacityMask documentation page and it looked like it had the properly transparent background, but it didn't. When I modified the image to actually have transparency, everything worked.

        1 Reply Last reply
        0

        • Login

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