gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
pyqt treeview 设置节点变灰
- User
pyqt treeview 设置节点变灰
- Assistant
您可以使用
setForeground()方法将节点的前景色设置为灰色,来使节点变灰色。代码如下:from PyQt5.QtGui import QColor from PyQt5.QtWidgets import QTreeView, QApplication, QStandardItemModel, QStandardItem app = QApplication([]) # 创建一个标准项模型 model = QStandardItemModel() treeView = QTreeView() treeView.setModel(model) # 插入节点 item1 = QStandardItem('Item 1') item2 = QStandardItem('Item 2') item3 = QStandardItem('Item 3') model.appendRow([item1, item2, item3]) # 将item2变灰 gray_color = QColor(150, 150, 150) item2.setForeground(gray_color) treeView.expandAll() treeView.show() app.exec_()在上面的代码中,我们先创建了一个标准项模型并在树视图中展示,然后在模型中插入了三个节点。最后使用
setForeground()方法将第二个节点的前景色设置为灰色。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.