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. Canvas 2d fill color by rgba string
Forum Updated to NodeBB v4.3 + New Features

Canvas 2d fill color by rgba string

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.8k 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.
  • P Offline
    P Offline
    PunyOne
    wrote on last edited by
    #1

    I had some troubles with color setting via standard HTML encoding (turned out to be because the Qt format is AARRGGBB, was expecting RRGGBBAA). I used 'rgba(.....)' instead, but I am getting some weird behaviour. Have a sufficiently big canvas and the following onPaint function, then the problems are as listed in the comments:

    @
    onPaint: {
    var context = getContext("2d")
    context.clearRect(0, 0, width, height)
    context.beginPath()

                context.fillStyle = "green"
    
                //  should be red, assignment failed, is green
                context.fillStyle = "rgba(1.0,0.0,0.0,1.0)"
                context.fillRect(50, 50, 100, 50)
                context.fill()
    
                // Should be transparent and red, assignment failed, is green
                context.fillStyle = "rgba(0.99,0.0,0.0,0.1)"
                context.fillRect(200, 50, 100, 50)
                context.fill()
    
                // Should be transparent, has the right colour, but full opacity
                context.fillStyle = "rgba(255,0,0,10)"
                context.fillRect(350, 50, 100, 50)
                context.fill()
    
                // This works, which, frankly...
                context.fillStyle = "rgba(255,0,0,0.1)"
                context.fillRect(500, 50, 100, 50)
                context.fill()
    

    }
    @

    Tested with QT 5.4 on Ubuntu 14.04

    RESOLVED:
    The last format is indeed correct, as detailed in: http://doc.qt.io/qt-5/qml-qtquick-context2d.html#fillStyle-prop

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

      Hi,

      As per "this":http://doc.qt.io/qt-5/qml-qtquick-context2d.html#fillStyle-prop the last one in your example is the valid format. Check out the other supported formats.

      157

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PunyOne
        wrote on last edited by
        #3

        [quote author="p3c0" date="1423716663"]Hi,

        As per "this":http://doc.qt.io/qt-5/qml-qtquick-context2d.html#fillStyle-prop the last one in your example is the valid format. Check out the other supported formats.[/quote]

        Thank you for the answer, I missed this paragraph altogether.

        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