from PySide2.QtWidgets import *
from PySide2.QtGui import *
class TreeComboBox(QComboBox):
def __init__(self, *args):
super().__init__(*args)
self.__skip_next_hide = False
tree_view = QTreeView(self)
self.setView(tree_view)
self.tree_view = tree_view
app = QApplication([])
combo = TreeComboBox()
combo.resize(200, 30)
parent_item = QStandardItem('Item 1')
parent_item.appendRow([QStandardItem('Child'), QStandardItem('Yesterday')])
parent_item.appendRow([QStandardItem('Child1'), QStandardItem('Yesterday')])
model = QStandardItemModel()
model.appendRow([parent_item, QStandardItem('Today')])
model.appendRow([QStandardItem('Item 2'), QStandardItem('Today')])
model.setHeaderData(0, Qt.Horizontal, 'Name', Qt.DisplayRole)
model.setHeaderData(1, Qt.Horizontal, 'Date', Qt.DisplayRole)
combo.setModel(model)
combo.tree_view.expandAll()
combo.setCurrentIndex(model.createIndex(0,0).row())
combo.show()
app.exec_()
combo.setCurrentIndex(model.createIndex(0,0).row()) 这句话默认选择了第一行
我想选择child1 应该怎么写