QTextEdit.insertHtml() 非常慢
我实际上已经放弃了让它跑得更快的尝试。
我最大的问题是,当我插入 html 时,应用程序速度慢得像爬行一样。 我有一个进度条,并且我正在调用
QCoreApplication.processEvents()
(顺便说一句,我正在使用 pyqt)
我可以将 insertHtml() 放入不同的线程中,这样我就不会出现无响应的界面吗? 我该怎么办呢?我研究过 QThread 和 QThreadPool,但不太确定从哪里开始。
I've given up on actually trying to make it go faster.
My biggest problem is that when I'm inserting the html, the application slows down to a crawl.
I have a progressbar, and I'm calling
QCoreApplication.processEvents()
(I'm using pyqt, by the way)
Can I put insertHtml() into a different thread, so I don't have an unresponsive interface?
How would I go about that? I've looked into QThread and QThreadPool, and I'm not quite sure where to begin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到了这个问题,以下是我为使其更快而采取的一些措施:
这应该消除不必要的开销。
另外,当插入大量文本时,最好关闭屏幕更新:
Qt 文档中的某处建议这样做,但我现在找不到该位置。
[编辑]
我在文档中偶然发现了这个地方(正好赶上它们被 QT5 grinn 过时了)http://qt-project.org/doc/qt-4.8/qwidget.html#updatesEnabled-prop
I had this problem as well, here are a few things I did to make it faster:
This should get rid of unneeded overhead.
Also when inserting large amounts of text its good to turn off screen updates:
This was recommended somewhere in the Qt documentation but I can't find the spot just now.
[Edit]
I stumbled across the spot in the Docs (just in time for them to be outdated by QT5 grinn) http://qt-project.org/doc/qt-4.8/qwidget.html#updatesEnabled-prop
所以,不。不幸的是,您无法在线程中执行该操作。
编辑:从技术上讲,这是可能的。我只是写了一个简短的代码片段,但是以这种方式使用 Qt GUI 对象是非常不安全的。
So, no. Unfortunately you cannot perform that operation in a thread.
Edit: Technically, it is possible. I just wrote a short snippet that did so, however using Qt GUI objects in that way is highly unsafe.