我有一个带有 QListWidget 的表单,我在其中反复添加新项目。这一切都完美无瑕,除了事情:无论我通过什么标志,这些物品都是三态的。因此,必须单击该项目两次以选中/取消选中它们。我应该怎么做才能使它们成为正常的双态?
小部件是这样创建的:
def _locationDetails(self):
self.locationDetails = QListWidget()
self.locationDetails.setFixedHeight(50)
return self.locationDetails
end 项目添加如下:
def addLocationDetail(self, text, checked = True):
item = QListWidgetItem(text)
item.setFlags(QtCore.Qt.ItemIsUserCheckable |
QtCore.Qt.ItemIsSelectable |
QtCore.Qt.ItemIsEnabled)
item.setCheckState(checked)
self.locationDetails.addItem(item)
我调用添加新项目的代码如下:
# resolve location:
waypoint.getLocationDetails()
self.locationDetails.clear()
self.addLocationDetail("location=%s" % waypoint.location)
self.addLocationDetail("department=%s" % waypoint.department)
self.addLocationDetail("country=%s" % waypoint.country)