本文整理汇总了Python中PyQt5.QtWidgets.QTableView.isColumnHidden方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.isColumnHidden方法的具体用法?Python QTableView.isColumnHidden怎么用?Python QTableView.isColumnHidden使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.isColumnHidden方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ListView
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import isColumnHidden [as 别名]
class ListView(QStackedWidget):
PAGE_EMPTY = 0
PAGE_LISTVIEW = 1
def __init__(self, parent = None):
super(ListView, self).__init__(parent=parent)
self.emptyMessage = QLabel("no elements defined yet")
self.emptyMessage.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter )
self.emptyMessage.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.addWidget(self.emptyMessage)
self._table = QTableView()
self.addWidget(self._table)
self._table.clicked.connect(self.tableViewCellClicked)
self._table.doubleClicked.connect(self.tableViewCellDoubleClicked)
self._table.verticalHeader().sectionMoved.connect(self.rowMovedTest)
self._table.setShowGrid(False)
def resetEmptyMessage(self,pystring):
self.emptyMessage.setText(pystring)
def tableViewCellClicked(self, modelIndex):
'''
Reimplemt this function to get interaction when double click
:param modelIndex:
'''
# if (modelIndex.column() == self.model.ColumnID.Delete and
# not self._table.model().flags(modelIndex) == Qt.NoItemFlags):
# self._table.model().removeRow(modelIndex.row())
#
def tableViewCellDoubleClicked(self, modelIndex):
'''
Reimplement this function to get interaction when single click
:param modelIndex:
'''
# if modelIndex.column() == self.model.ColumnID.Color:
# self._colorDialog.setBrushColor(self._table.model()[modelIndex.row()].brushColor())
# self._colorDialog.setPmapColor (self._table.model()[modelIndex.row()].pmapColor())
# self._colorDialog.exec_()
# #print "brush color = {}".format(self._colorDialog.brushColor().name())
# #print "pmap color = {}".format(self._colorDialog.pmapColor().name())
# self._table.model().setData(modelIndex, (self._colorDialog.brushColor(),
# self._colorDialog.pmapColor ()))
def rowMovedTest(self, logicalIndex, oldVisualIndex, newVisualIndex):
logger.debug( "{} {} {}".format(logicalIndex, oldVisualIndex, newVisualIndex) )
def _setListViewLook(self):
table = self._table
#table.setDragEnabled(True)
table.setAcceptDrops(True)
table.setFocusPolicy(Qt.NoFocus)
table.setShowGrid(False)
table.horizontalHeader().hide()
table.verticalHeader().hide()
#table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
table.setSelectionMode(QAbstractItemView.SingleSelection)
table.setSelectionBehavior(QAbstractItemView.SelectRows)
def selectRow(self, *args, **kwargs):
self._table.selectRow(*args, **kwargs)
def _onRowsChanged(self, parent, start, end):
model = self._table.model()
if model and model.rowCount() > 0:
self.setCurrentIndex(self.PAGE_LISTVIEW)
else:
self.setCurrentIndex(self.PAGE_EMPTY)
if self.parent()!=None: self.parent().updateGeometry()
def setModel(self, model):
QTableView.setModel(self._table, model)
self._table.setSelectionModel(model._selectionModel)
if model.rowCount() > 0:
self.setCurrentIndex(self.PAGE_LISTVIEW)
else:
self.setCurrentIndex(self.PAGE_EMPTY)
model.rowsInserted.connect(self._onRowsChanged)
model.rowsRemoved.connect(self._onRowsChanged)
self.model=model
self._setListViewLook()
@property
def allowDelete(self):
return not self._table.isColumnHidden(self.model.ColumnID.Delete)
@allowDelete.setter
def allowDelete(self, allow):
self._table.setColumnHidden(self.model.ColumnID.Delete, not allow)
#.........这里部分代码省略.........