问题描述
我想在 QGraphicsScene 中实现 arc.我希望在点击三个点时我的弧应该被绘制,这样在点击三个点时就会绘制弧,其中第一个点将是弧的起点,第二个将是弧上的任何点,第三个将是弧的终点.我曾尝试研究 drawArc 函数,但对 startangle 和 spanangle 感到困惑.我无法动态设置它们.请给我建议一些方法来继续.
I want to implement arc in QGraphicsScene. I want that on clicking of three points my arc should be drawn such that on clicking of three points arc is drawn where first point will be starting of arc, second will be any point on arc and third will be end point of arc. I have tried studing drawArc function but got confused with startangle and spanangle. I was unable to set them dynamically. Please suggest me some way to proceed.
我尝试将解决方案嵌入到我的项目中,但出现以下错误:
I tried the solution to embend it in my project but got the following error:
你能帮我解决这个问题吗?我正在为我的项目提供一部分代码.在cadgraphicsscene的mousepress事件中,我做了以下事情.
Can you please help me out to solve the problem. I am giving a part of code to my project. In mousepress event of cadgraphicsscene I have done following thing.
cadgraphicsscene.cpp
cadgraphicsscene.cpp
arc.cpp
arc.h
请帮我解决这个错误.
推荐答案
QGraphicsItem 的一个子类,取 3 个点,并用圆弧与三个点相交.第二点总是在中间.(可选性和其他属性尚未完全实现或测试).
A Subclass of QGraphicsItem, that takes 3 points, and intersects the three with an arc of a circle. The second point is always in the middle. (Selectablity and other properties haven't been fully implemented or tested).
注意:Qt Creator 包含更高级的子类 QGraphicsItem
示例,例如 Colliding Mice 和 40,000 个筹码示例.
Note: Qt Creator includes more advanced examples of subclassed QGraphicsItem
s such as Colliding Mice, and 40,000 chips examples.
http://qt-project.org/doc/qt-5/examples-graphicsview.html
还要从 QGraphicsItem
启用 QObject
信号和槽以及属性,您应该使用 QGraphicsObject
.
Also to enable QObject
signals and slots and properties from a QGraphicsItem
, you should use QGraphicsObject
.
注意:添加到 github 此处.
Note: added onto github here.
arcgraphicsitem.h
arcgraphicsitem.h
arcgraphicsitem.cpp
arcgraphicsitem.cpp
希望有帮助
这篇关于QGraphicsScene中的圆弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!