本文整理汇总了Python中PyQt5.QtWidgets.QTableView.mapToGlobal方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.mapToGlobal方法的具体用法?Python QTableView.mapToGlobal怎么用?Python QTableView.mapToGlobal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.mapToGlobal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FilterableTable
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import mapToGlobal [as 别名]
#.........这里部分代码省略.........
def update_filterbox(self):
"""fills the filter-combobox with the header values
after the model has been created and set
"""
column_num = self.model.columnCount()
if self.header_dic:
columns = [self.header_dic[i] for i in self.header_dic]
else:
columns = [self.proxy.headerData(i, Qt.Horizontal) for i in range(column_num)]
self.filter_cb.addItems(columns)
def create_filter_model(self):
"""creates the filter-proxy-model on top of self.model
"""
self.log.debug("Creating filter model...")
self.proxy = QSortFilterProxyModel(self)
if self.add_color_proxy:
(allele_status_column, lab_status_column) = self.add_color_proxy
self.log.debug("adding color filter to columns {} and {}".format(allele_status_column, lab_status_column))
self.color_proxy = ColorProxyModel(self, allele_status_column, lab_status_column)
self.color_proxy.setSourceModel(self.model)
self.proxy.setSourceModel(self.color_proxy)
else:
self.proxy.setSourceModel(self.model)
self.table.setSortingEnabled(True)
self.table.setModel(self.proxy)
def on_filter_cb_IndexChanged(self, index):
"""restricts RegEx filter to selected column
"""
self.log.debug("Combobox: colum {} selected".format(index))
self.proxy.setFilterKeyColumn(index)
def on_filter_entry_textChanged(self, text):
"""stores content of filter_entry as self.text
"""
self.log.debug("filter text: '{}'".format(text))
self.filter_text = text
def on_filter_btn_clicked(self):
"""activates RegEx filter to current content of filter_entry and filter_cb
"""
column = self.filter_cb.currentIndex()
self.log.debug("Filtering column {} for '{}'".format(column, self.filter_text))
self.proxy.setFilterKeyColumn(column)
search = QRegExp(self.filter_text, Qt.CaseInsensitive, QRegExp.RegExp)
self.proxy.setFilterRegExp(search)
def on_header_sectionClicked(self, logicalIndex):
"""opens a dialog to choose between all unique values for this column,
or revert to 'All'
"""
self.log.debug("Header clicked: column {}".format(logicalIndex))
self.logicalIndex = logicalIndex
menuValues = QMenu(self)
self.signalMapper = QSignalMapper(self)
self.filter_cb.setCurrentIndex(self.logicalIndex)
self.filter_cb.blockSignals(True)
self.proxy.setFilterKeyColumn(self.logicalIndex)
valuesUnique = [str(self.model.index(row, self.logicalIndex).data())
for row in range(self.model.rowCount())
]
actionAll = QAction("All", self)
actionAll.triggered.connect(self.on_actionAll_triggered)
menuValues.addAction(actionAll)
menuValues.addSeparator()
for actionNumber, actionName in enumerate(sorted(list(set(valuesUnique)))):
action = QAction(actionName, self)
self.signalMapper.setMapping(action, actionNumber)
action.triggered.connect(self.signalMapper.map)
menuValues.addAction(action)
self.signalMapper.mapped.connect(self.on_signalMapper_mapped)
headerPos = self.table.mapToGlobal(self.header.pos())
posY = headerPos.y() + self.header.height()
posX = headerPos.x() + self.header.sectionViewportPosition(self.logicalIndex)
menuValues.exec_(QPoint(posX, posY))
def on_actionAll_triggered(self):
"""reverts table to unfiltered state
"""
self.log.debug("Unfiltering...")
filterString = QRegExp("", Qt.CaseInsensitive, QRegExp.RegExp)
self.proxy.setFilterRegExp(filterString)
self.filter_entry.setText("")
def on_signalMapper_mapped(self, i):
"""filters current column to mapping text
"""
text = self.signalMapper.mapping(i).text()
self.log.debug("Filtering column {} to '{}'".format(self.logicalIndex, text))
filterString = QRegExp(text, Qt.CaseSensitive, QRegExp.FixedString)
self.proxy.setFilterRegExp(filterString)