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. Drawing tile-image in canvas object
Forum Updated to NodeBB v4.3 + New Features

Drawing tile-image in canvas object

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 260 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.
  • N Offline
    N Offline
    NightFury
    wrote on last edited by
    #1

    I am using a canvas like this,

    Canvas
    {
    	id: canvas
    	x: 0
    	y: 0
    	height: 200
    	width: 400
    
    	onAvailableChanged:
    	{
    	if(canvas.available)
    	{
    			var ctx=canvas.getContext("2d")
    			ctx.fillStyle="transparent"
    			ctx.fillRect(base.x,
    						base.y,
    						 base.width,base.height)
    			if(bgimge)
    			{
    				ctx.fillStyle="white"
    				ctx.fillRect(0,0,200,400)
    				ctx.drawImage(bgimge,0,0,200,400)
    			}
    		}
    	}
    
    	onPaint:
    	{
    		var ctx=canvas.getContext("2d")
    		ctx.beginPath()
    		ctx.strokeStyle=penColour
    		ctx.lineWidth=penWidth
    		ctx.pixelSize="100px"
    
    		ctx.moveTo(canvas.lastX,canvas.lastY)
    		lastX=mouseArea.mouseX
    		lastY=mouseArea.mouseY
    		ctx.lineTo(canvas.lastX,canvas.lastY)
    
    		ctx.stroke()
    	}
    }
    

    Here I am able to draw the background image, is there any way to fill the image in tile mode ?

    MarkkyboyM 1 Reply Last reply
    0
    • N NightFury

      I am using a canvas like this,

      Canvas
      {
      	id: canvas
      	x: 0
      	y: 0
      	height: 200
      	width: 400
      
      	onAvailableChanged:
      	{
      	if(canvas.available)
      	{
      			var ctx=canvas.getContext("2d")
      			ctx.fillStyle="transparent"
      			ctx.fillRect(base.x,
      						base.y,
      						 base.width,base.height)
      			if(bgimge)
      			{
      				ctx.fillStyle="white"
      				ctx.fillRect(0,0,200,400)
      				ctx.drawImage(bgimge,0,0,200,400)
      			}
      		}
      	}
      
      	onPaint:
      	{
      		var ctx=canvas.getContext("2d")
      		ctx.beginPath()
      		ctx.strokeStyle=penColour
      		ctx.lineWidth=penWidth
      		ctx.pixelSize="100px"
      
      		ctx.moveTo(canvas.lastX,canvas.lastY)
      		lastX=mouseArea.mouseX
      		lastY=mouseArea.mouseY
      		ctx.lineTo(canvas.lastX,canvas.lastY)
      
      		ctx.stroke()
      	}
      }
      

      Here I am able to draw the background image, is there any way to fill the image in tile mode ?

      MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by Markkyboy
      #2

      Please give enough code to make a working example.

      Your current code only gives errors in console and a blank screen. Nothing drawn/shown.

      bgimge, penColour, penWidth, mouseArea, etc, have no reference.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      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