简体   繁体   English

如何使用Qt QGraphicsitem设计轴

[英]How to design an axis, by using Qt QGraphicsitem

I want to implement a axis of a coordinate. 我想实现一个坐标轴。 What I want to do is that: 我想做的是:

  • when I drag the most head point of this axis, only the length of axis will be changed with mouse move. 当我拖动该轴的最前端时,只有轴的长度会随着鼠标移动而改变。
  • when I drag the body of this axis, only the direction of axis will be changed. 当我拖动该轴的主体时,只会更改轴的方向。

How to do that? 怎么做? I think that, I can use two QgraphicsItems ( head , body ) to represent a axis. 我认为,我可以使用两个QgraphicsItems( headbody )来表示一个轴。 When the head is dragging, do the scaling. 头部拖动时,进行缩放。 When the body is dragging, it does rotation. 身体拖动时,它会旋转。

Is there any better solution to do that? 有更好的解决方案吗?

You could do it as one graphics item, with the drag behaviour changing depending on where you click, but your suggestion is reasonable. 您可以将其作为一个图形项来完成,拖动行为会根据您单击的位置而变化,但是您的建议是合理的。

For your method, the arrow head will need to be a child item of the arrow body - so when you rotate the body it moves appropriately, and you will need a custom hack in the mouse click / mouse move events for the arrow head to resize the body appropriately. 对于您的方法,箭头必须是箭头主体的子项-因此,当您旋转箭头主体时,箭头会适当移动,并且需要在鼠标单击/鼠标移动事件中进行自定义修改,以调整箭头的大小身体适当。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM