简体   繁体   English

Qt,在调用QPainter :: drawText()时获取文本

[英]Qt, Getting the text when QPainter::drawText() is called

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). 我有一个QPainter对象,想获取每次调用QPainter :: drawText时绘制的字符串,就像我可以将插槽连接到该信号(该信号不存在,所以我不能)一样。 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? 我已经阅读了一些有关使用setProperty方法将drawText方法重定向到自定义方法,并将其传递给drawText指针的内容,但是我从未尝试过,对我来说似乎有点过头了。如何获取drawText绘制的文本字符串?

Edit: It would also be ok if instead of getting the text form the painter, we get it from the PaintEngine 编辑:如果不是从painter获取文本,而是从PaintEngine获取文本,也可以

Any help is appreciated, Thanks 任何帮助表示赞赏,谢谢

I guess the only reliable way is to subclass QPainter, reimplement the drawText() method and add some debug text in your own class. 我猜唯一可靠的方法是继承QPainter的子类,重新实现drawText()方法,并在自己的类中添加一些调试文本。 I doubt QPainter has any facilities to capture a signal or something, since most of the drawing methods are speed critical. 我怀疑QPainter是否具有捕获信号或其他东西的功能,因为大多数绘图方法对速度至关重要。

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

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