擅长:python、mysql、java
<p>在模型的<code>data()</code>方法中,可以添加代码来根据项的内容设置字体。例如,如果你想在一个特定的行中加粗所有的内容</p>
<pre><code>def data(self, index, role):
if role == QtCore.Qt.FontRole:
if index.row() == 1:
boldFont = QtGui.QFont()
boldFont.setBold(True)
return boldFont
</code></pre>
<p>您只需要一种方法在给定分支的索引时检索它的名称。这取决于树模型的实现。在</p>
<q> Qt/VIEW <a href="http://doc.qt.nokia.com/latest/modelview.html" rel="nofollow">tutorial</a>有一个很好的例子,虽然它是C++的。请看第2.2节(用角色扩展只读示例)。在</p>