本文整理汇总了Python中PySide.QtGui.QTableView.setStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setStyleSheet方法的具体用法?Python QTableView.setStyleSheet怎么用?Python QTableView.setStyleSheet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableView
的用法示例。
在下文中一共展示了QTableView.setStyleSheet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LayerListWidget
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setStyleSheet [as 别名]
class LayerListWidget(_ParameterWidget):
def __init__(self, parameter, parent=None):
_ParameterWidget.__init__(self, parameter, parent)
# Variables
model = _LayerModel()
self._material_class = Material
# Actions
act_add = QAction(getIcon("list-add"), "Add layer", self)
act_remove = QAction(getIcon("list-remove"), "Remove layer", self)
act_clean = QAction(getIcon('edit-clear'), "Clear", self)
# Widgets
self._cb_unit = UnitComboBox('m')
self._cb_unit.setUnit('um')
self._tbl_layers = QTableView()
self._tbl_layers.setModel(model)
self._tbl_layers.setItemDelegate(_LayerDelegate())
header = self._tbl_layers.horizontalHeader()
header.setResizeMode(QHeaderView.Stretch)
header.setStyleSheet('color: blue')
self._tlb_layers = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self._tlb_layers.addWidget(spacer)
self._tlb_layers.addAction(act_add)
self._tlb_layers.addAction(act_remove)
self._tlb_layers.addAction(act_clean)
# Layouts
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
sublayout = QHBoxLayout()
sublayout.addStretch()
sublayout.addWidget(QLabel('Thickness unit'))
sublayout.addWidget(self._cb_unit)
layout.addLayout(sublayout)
layout.addWidget(self._tbl_layers)
layout.addWidget(self._tlb_layers)
self.setLayout(layout)
# Signals
self.valuesChanged.connect(self._onChanged)
self.validationRequested.connect(self._onChanged)
act_add.triggered.connect(self._onAdd)
act_remove.triggered.connect(self._onRemove)
act_clean.triggered.connect(self._onClear)
self._tbl_layers.doubleClicked.connect(self._onDoubleClicked)
model.dataChanged.connect(self.valuesChanged)
model.rowsInserted.connect(self.valuesChanged)
model.rowsRemoved.connect(self.valuesChanged)
self.validationRequested.emit()
def _onChanged(self):
if self.hasAcceptableInput():
self._tbl_layers.setStyleSheet("background: none")
else:
self._tbl_layers.setStyleSheet("background: pink")
def _onDoubleClicked(self, index):
if index.column() != 0:
return
model = self._tbl_layers.model()
materials = model.materials(index)
if len(materials) == 0:
dialog = get_material_dialog_class(self._material_class)()
elif len(materials) == 1:
dialog = get_material_dialog_class(self._material_class)()
dialog.setValue(materials[0])
else:
dialog = MaterialListDialog()
dialog.setMaterialClass(self._material_class)
dialog.setValues(materials)
dialog.setReadOnly(self.isReadOnly())
if not dialog.exec_():
return
model.setData(index, dialog.values())
def _onAdd(self):
index = self._tbl_layers.selectionModel().currentIndex()
model = self._tbl_layers.model()
model.insertRows(index.row() + 1)
# Show material dialog right away
index = model.createIndex(index.row() + 1, 0)
#.........这里部分代码省略.........