<p>如果我正确地理解了你的问题,你只想改变文本的颜色,对吧?
你可以用css把<code>StyleSheets</code>分配给你的<code>QWidgets</code>,文档<a href="http://doc.qt.digia.com/4.2/stylesheet.html" rel="nofollow">here</a>。</p>
<p>样本如下:</p>
<pre><code>from PyQt4 import QtGui, QtCore
class Window(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
self._offset = 200
self._closed = False
self._maxwidth = self.maximumWidth()
self.widget = QtGui.QWidget(self)
self.listbox = QtGui.QListWidget(self.widget)
self.editor = QtGui.QTextEdit(self)
self.editor.setStyleSheet("QTextEdit {color:red}")
layout = QtGui.QHBoxLayout(self)
layout.addWidget(self.widget)
layout.addWidget(self.editor)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.move(500, 300)
window.show()
sys.exit(app.exec_())
</code></pre>
<h2>编辑</h2>
<p>或者可以将样式表设置为所有的<code>QTextEdit</code>,请尝试以下操作:</p>
<pre><code>......
app = QtGui.QApplication(sys.argv)
app.setStyleSheet("QTextEdit {color:red}")
......
</code></pre>