使用 QT 调整橡皮筋大小
我想创建一个可调整大小的选择工具来用鼠标选择图像的一部分。 我想用 QT 来完成这个任务,我有一个可用的 QRubberBand 来创建基本选择。
下一步是使用鼠标调整该选择的大小。 因此,如果您单击并拖动一个角,大小会相应变化,如果您在选区内单击并拖动,它应该移动选区。
现在我的想法是子类化 QRubberBand 并重写 PaintEvent 方法以在每个角上绘制一个大点并在这些点上执行鼠标事件。 但我想知道是否有人有更聪明/更好的方法来做到这一点?
我想听听对此的一些想法。 提前致谢。
I want to create a resizeable selection tool to select a part of an image with the mouse.
I want to accomplish this with QT, i have a working QRubberBand to create a basic selection.
Next step is to make that selection resizeable with the mouse.
So if you click&drag a corner the size changes accordingly and if you click&drag inside the selection it should move the selection.
now my idea is subclassing QRubberBand and overriding the paintEvent method to paint a big dot on every corner and perform the mouseevents on those dots.
But i was wondering if anyone has a smarter/better way of doing this?
i'd like to hear some ideas on this.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前也做过类似的事情。我使用 QGraphicsView 而不是 QWidget,这使得开发更加容易。我使用 QGraphicsItem 作为“橡皮筋”。 QGraphicsView 已经处理了大量的用户交互,因此我不必费心重新实现 QWidget::mouseMove() 事件等。此外,由于 QGraphicsView 优化,性能比 QWidget 快得多。
希望这有帮助
I did something similar before. I used QGraphicsView instead of QWidget which made the development much easier. I used QGraphicsItem as the "rubber band". QGraphicsView already handles a lot of user interaction so I didn't have to bother with reimplementing QWidget::mouseMove() events, etc. Plus the performance was much faster than on QWidget because of QGraphicsView optimizations.
Hope this helps
我刚刚为我的 Qt 图像和矢量查看器实现了任意交互式叠加图形的通用框架。请参阅 https://github.com/dov/Qviv/tree/Lasso 中的分支 Lasso /套索。您可以使用 scons 编译它,然后运行 testLasso 来测试它。目前该测试实现了一个可移动的半透明卡尺,但您可以轻松地将其更改为您想要的任何图形。请注意,Lasso 子目录目前完全独立于 Qviv 项目的其余部分。
I just implemented a general framework for arbitrary interactive overlay graphics for my Qt image and vector viewer. Please see the branch Lasso in https://github.com/dov/Qviv/tree/Lasso/Lasso . You can compile it with
scons
and then runtestLasso
to test it. Currently the test implements a movable semitransparent caliper, but you can easily change it to any graphics you desire. Note that the Lasso sub directory is currently completely independent of the rest of the Qviv project.