Qt,调用 QPainter::drawText() 时获取文本
我有一个 QPainter 对象,并且希望获取每当调用 QPainter::drawText 时绘制的字符串,就像我可以将一个插槽连接到该信号一样(该信号不存在,所以我不能)。 最好的方法是什么?我读过一些关于使用 setProperty 方法将drawText方法重定向到自定义方法,并将其传递给drawText的指针的内容,但我从未尝试过,而且对我来说这似乎有点矫枉过正。 有人对如何获取由drawText绘制的文本字符串有更好的想法吗?
编辑:如果我们不从画家那里获取文本,而是从 PaintEngine 获取文本,那么也可以。
感谢任何帮助,谢谢
I have a QPainter object and would like to obtain the string that is drawn whenever QPainter::drawText is called, as I would if I could connect a slot to that signal (which doesn't exist, so I can't).
What would be the best way to do this? I have read some stuff about redirecting the drawText method to a custom one using the setProperty method, and passing it a pointer to drawText, but I've never tried it, and it seems like overkill to me..
Anyone have a better idea about how to obtain the String of text that is drawn by drawText?
Edit: It would also be ok if instead of getting the text form the painter, we get it from the PaintEngine
Any help is appreciated, Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想唯一可靠的方法是子类化 QPainter,重新实现 drawText() 方法并在您自己的类中添加一些调试文本。我怀疑 QPainter 是否有任何捕获信号或其他东西的设施,因为大多数绘图方法都对速度至关重要。
I guess the only reliable way is to subclass QPainter, reimplement the drawText() method and add some debug text in your own class. I doubt QPainter has any facilities to capture a signal or something, since most of the drawing methods are speed critical.