如何在QTextBrowser (PyQt4)中使用Python在特定的必要点添加图像?

时间:2021-08-21 21:20:09

I am doing Text mining using python. I created a GUI using QT and transformed it into python snippet using PyQt4. I have QTextBrowser which indicates the sentiment index of the passage. Based on the score of the sentiment index I want to add different images into the Qtextbrowser. Below which I have added the screenshot of my tool.

我正在使用python进行文本挖掘。我使用QT创建了一个GUI,并使用PyQt4将其转换为python代码片段。我有QTextBrowser,它指示文章的情绪指数。根据情绪指数的得分,我想在Qtextbrowser中添加不同的图片。下面我添加了工具的屏幕截图。

https://drive.google.com/file/d/0B-bFVFevEa-yMUZUMnc2UWN4T00/edit?usp=sharing

https://drive.google.com/file/d/0B-bFVFevEa-yMUZUMnc2UWN4T00/edit?usp=sharing

Below image is the screenshot of the tool which I have created for Text mining. At the the bottom of the right hand panel , you can see the score of sentiment of the passage. Now I want to add the image on the highlighted square box area depending upon the score of the sentiment.

下图是我为文本挖掘创建的工具的屏幕截图。在右手面板的底部,你可以看到这篇文章的情绪评分。现在我想要添加图像在突出的方形框区域,取决于情绪的分数。

How to add the image at the particular point in the QtextBrowser ?

如何在QtextBrowser的特定点添加图像?

1 个解决方案

#1


0  

http://pyqt.sourceforge.net/Docs/PyQt4/qtextbrowser.html#loadResource

http://pyqt.sourceforge.net/Docs/PyQt4/qtextbrowser.html loadResource

Example:

例子:

import sys
from PyQt4 import QtGui, QtCore

class myTextBrowser(QtGui.QTextBrowser):
    def loadResource (self, type, name):
        return QtGui.QPixmap("test.jpg")

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    a = myTextBrowser()
    a.document().setHtml("""My image :<br /><img src="test.jpg"/>""")
    a.show()
    sys.exit(app.exec_())

#1


0  

http://pyqt.sourceforge.net/Docs/PyQt4/qtextbrowser.html#loadResource

http://pyqt.sourceforge.net/Docs/PyQt4/qtextbrowser.html loadResource

Example:

例子:

import sys
from PyQt4 import QtGui, QtCore

class myTextBrowser(QtGui.QTextBrowser):
    def loadResource (self, type, name):
        return QtGui.QPixmap("test.jpg")

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    a = myTextBrowser()
    a.document().setHtml("""My image :<br /><img src="test.jpg"/>""")
    a.show()
    sys.exit(app.exec_())