本文整理汇总了Python中AnyQt.QtGui.QStandardItemModel.setHorizontalHeaderItem方法的典型用法代码示例。如果您正苦于以下问题:Python QStandardItemModel.setHorizontalHeaderItem方法的具体用法?Python QStandardItemModel.setHorizontalHeaderItem怎么用?Python QStandardItemModel.setHorizontalHeaderItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel.setHorizontalHeaderItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_groups
# 需要导入模块: from AnyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from AnyQt.QtGui.QStandardItemModel import setHorizontalHeaderItem [as 别名]
def set_groups(self, keys, groups, relevant_keys, relevant_items,
all_values, uniquepos):
"""Set the current data groups and update the Group widget
"""
layout = QVBoxLayout()
header_widths = []
header_views = []
palette = self.palette()
all_values = all_values.keys()
def for_print(rd):
attrs = []
for d in rd:
attr = Orange.data.ContinuousVariable(next(inactive_name_gen))
attr.attributes.update(d)
attrs.append(attr)
return Orange.data.Domain(attrs, None)
for separatev, domain in [(None, for_print(relevant_items))] + groups:
label = None
if separatev is not None:
ann_vals = " <b>|</b> ".join(["<b>{0}</b> = {1}".format(key,val) \
for key, val in zip(keys, separatev)])
label = QLabel(ann_vals)
model = QStandardItemModel()
for i, attr in enumerate(domain.attributes):
item = QStandardItem()
if separatev is not None:
isunique = uniquepos[separatev][i]
else:
isunique = all(a[i] for a in uniquepos.values())
if str(attr.name).startswith("!!missing "): # TODO: Change this to not depend on name
header_text = ["{0}={1}".format(key, attr.attributes.get(key, "?")) \
for key in all_values if key not in relevant_items[i]]
header_text = "\n".join(header_text) if header_text else "Empty"
item.setData(header_text, Qt.DisplayRole)
item.setFlags(Qt.NoItemFlags)
item.setData(QColor(Qt.red), Qt.ForegroundRole)
item.setData(palette.color(QPalette.Disabled, QPalette.Window), Qt.BackgroundRole)
item.setData("Missing feature.", Qt.ToolTipRole)
elif str(attr.name).startswith("!!inactive "):
header_text = ["{0}={1}".format(key, attr.attributes.get(key, "?")) \
for key in all_values if key in relevant_items[i]]
header_text = "\n".join(header_text) if header_text else "No descriptor"
item.setData(header_text, Qt.DisplayRole)
item.setData(palette.color(QPalette.Disabled, QPalette.Window), Qt.BackgroundRole)
else:
header_text = ["{0}={1}".format(key, attr.attributes.get(key, "?")) \
for key in all_values if key not in relevant_items[i]]
header_text = "\n".join(header_text) if header_text else "Empty"
item.setData(header_text, Qt.DisplayRole)
item.setData(attr.name, Qt.ToolTipRole)
if not isunique:
item.setData(QColor(Qt.red), Qt.ForegroundRole)
model.setHorizontalHeaderItem(i, item)
attr_count = len(domain.attributes)
view = MyHeaderView(Qt.Horizontal)
view.setResizeMode(QHeaderView.Fixed)
view.setModel(model)
hint = view.sizeHint()
view.setMaximumHeight(hint.height())
widths = [view.sectionSizeHint(i) for i in range(attr_count)]
header_widths.append(widths)
header_views.append(view)
if label:
layout.addWidget(label)
layout.addWidget(view)
layout.addSpacing(8)
# Make all header sections the same width
width_sum = 0
max_header_count = max([h.count() for h in header_views])
for i in range(max_header_count):
max_width = max([w[i] for w in header_widths if i < len(w)] or [0])
for view in header_views:
if i < view.count():
view.resizeSection(i, max_width)
width_sum += max_width + 2
for h in header_views:
h.setMinimumWidth(h.length() + 4)
widget = QWidget()
widget.setLayout(layout)
widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum)
layout.activate()
max_width = max(h.length() for h in header_views) + 20
left, _, right, _ = self.getContentsMargins()
widget.setMinimumWidth(width_sum)
widget.setMinimumWidth(max_width + left + right)
self.groups_scroll_area.setWidget(widget)