- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 QML 文件,它绘制一个绿色圆圈(通过 QML 矩形)并在圆圈上绘制一个黑色圆弧(通过 Canvas 和 arcTo)。圆的位置和半径取决于窗口的大小。对于大多数尺寸来说,这似乎工作得很好,但对于某些尺寸来说,弧线就消失了。重现该行为的完整 main.qml 如下:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
height: 400
width: 400
Rectangle{
x:20
y:20
height: parent.height-40
width: parent.width-40
Rectangle{
id:circle
x:(parent.height<parent.width?parent.height:parent.width)/3
y:x
height:(parent.height<parent.width?parent.height:parent.width)/3
width: height
radius: height/2
border.color: 'green'
}
Canvas{
anchors.fill: parent
visible: true
onPaint: {
var ctx = getContext("2d");
ctx.strokeStyle = 'black';
ctx.lineWidth = 4;
var x = circle.x;
var y = circle.y;
var r = circle.radius;
ctx.beginPath();
ctx.moveTo(x,y+r);
ctx.arcTo(x,y+2*r,x+r,y+2*r,r);
ctx.stroke();
}
}
}
}
问题当然是这是否是 QML 中的错误或者我是否在某个地方犯了错误。我希望有人能帮助我。
最佳答案
对我来说看起来像是一个错误。好像和传入的坐标有关系:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
id: window
visible: true
height: 400
width: 400
Rectangle {
anchors.fill: parent
anchors.margins: 20
Canvas {
anchors.fill: parent
onPaint: {
var ctx = getContext("2d")
ctx.strokeStyle = 'black'
ctx.lineWidth = 4
var x = 0
var y = 0
var r = parent.height / 2
ctx.beginPath()
// Visible:
ctx.moveTo(120.33333333333333, 180.5)
ctx.arcTo(120.33333333333333, 240.66666666666666, 180.5, 240.66666666666666, 60.166666666666664)
// Not visible:
// ctx.moveTo(120.66666666666667, 181)
// ctx.arcTo(120.66666666666667, 241.33333333333334, 181, 241.33333333333334, 60.333333333333336)
ctx.stroke()
}
}
}
}
关于javascript - arcTo 有时不会在调整大小时绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33303122/
SVG specification 中的 ARCTO 与我们在 Canvas 中的有很大不同。我有一个用例,我将根据 SVG 规范获取数据,但我需要在 Canvas 上绘制它。 我试过这个,但我想我的
我有以下 QML 文件,它绘制一个绿色圆圈(通过 QML 矩形)并在圆圈上绘制一个黑色圆弧(通过 Canvas 和 arcTo)。圆的位置和半径取决于窗口的大小。对于大多数尺寸来说,这似乎工作得很好,
我正在处理一个图形编辑器的功能,我正在编辑圆弧,当形状是椭圆时,QPainterPath::arcTo 的行为并不像我预期的那样;当它是一个圆圈时,它按预期工作。 下面的两张图片显示了结果。在第一种情
我正在玩 HTML5 canvas,我的书上是这么说的 latest browser supports arcTo method and it has capabilities to remove a
所以我再次处理环形扇区,这不是我的强项。我可以在 Canvas 上很好地使用 .arc 方法,问题来自需要我的弧线成为路径的一部分。 例如: ctx.save(); ctx.arc(centerX
我正在尝试制作眼睛的白色部分: 但我不知道我做错了什么,也许这不是假设使用 arcTo,问题是我如何做眼 Angular ? function main() { var c2d = docum
我正在尝试绘制一个带圆角的矩形。我有一个执行此操作的 javascript 路径,但 javascript arcTo 方法采用一个矩形(定义其椭圆形),然后是一个设置扫描的参数。 但是,在 Andr
我有一个 List我希望能够添加到场景图形或绘制到 Canvas 。第一个很简单,因为我可以创建一个 Path 节点并将其添加到场景中。第二个需要来自 PathElement 的映射's to cal
我有 2 个点,由一条线连接,即起点和终点。 我想在它们之间绘制一条圆弧,但半径应该是动态的,具体取决于用户单击的位置。因此我有一个来自鼠标的第三个点,带有 XY 坐标。 如何绘制 ctx.arcTo
我想画出这样一条路径并填充它: 如果原点是坐标为 (x, y) 的红点。我应该在下面的三重点中写什么来绘制这条路径。我已经尝试了很多,但无法弄清楚 arcTo 是如何工作的。 path.mov
我正在制作一个我想用 JavaFX 制作的游戏的原型(prototype)。它需要角色/ Sprite 沿着弯曲的路径向前移动(基本上是向前跳跃到特定位置)。我尝试使用MoveTo(使用 Sprite
在以下代码中使用 arcTo 时出现错误,使用的是 Kinetic.js 5.1.0。 错误是'TypeError: context.arcTo is not a function' myshape
我已经成功地开始以 0 到 360 度的角度扫描,从而实现了一个动画绘图环。然而,当环的尾部以 360 度角与环的头部相遇时,所有绘图都消失了。 这是我在onDraw() 中的圆环代码
我在 Nexus 7 上运行我的代码,同时它仍然安装了 Android 4.3。然后我升级到 Android 4.4 并再次运行我的代码。以下是我对一个奇怪的 Canvas.drawArc()/Pat
我是一名优秀的程序员,十分优秀!