本文整理汇总了Python中PyQt5.QtWidgets.QTableView.setContextMenuPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setContextMenuPolicy方法的具体用法?Python QTableView.setContextMenuPolicy怎么用?Python QTableView.setContextMenuPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.setContextMenuPolicy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createLibraryPlaylisView
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setContextMenuPolicy [as 别名]
def createLibraryPlaylisView(self, uuid):
playlistModel = PlaylistModel(uuid)
playlistView = QTableView(self)
playlistView.setModel(playlistModel)
playlistView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
playlistView.setSortingEnabled(True)
playlistView.setSelectionBehavior(QAbstractItemView.SelectRows)
playlistView.setShowGrid(False)
playlistView.horizontalHeader().setSectionResizeMode(
QHeaderView.Stretch)
playlistView.doubleClicked.connect(self._doubleCLickedWidget)
playlistView.customContextMenuRequested.connect(
self.customMenuRequested)
self.playlistMappings[uuid] = playlistView
self.insertWidget(0, playlistView)
self.setCurrentWidget(self.playlistMappings[uuid])
示例2: FilterableTable
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setContextMenuPolicy [as 别名]
class FilterableTable(SQLTable):
"""a filterable Table Widget that displays content of an SQLite table;
for individual widgets, subclass
and overwrite the create_model method;
add_color_proxy should be an (INT allele_status-column, INT lab_status-column) tuple
"""
def __init__(self, log, mydb = ": memory :", add_color_proxy = False, header_dic = None):
super().__init__(log, mydb)
self.add_color_proxy = add_color_proxy
self.header_dic = header_dic
self.create_model()
self.fill_UI()
self.create_filter_model()
self.update_filterbox()
def fill_UI(self):
"""sets up the layout
"""
self.log.debug("\t- Setting up the table...")
self.table = QTableView()
self.table.setContextMenuPolicy(Qt.CustomContextMenu)
self.header = self.table.horizontalHeader() # table header
self.header.setSectionResizeMode(QHeaderView.ResizeToContents)
self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
self.table.setAlternatingRowColors(True)
# self.header.sectionClicked.connect(self.on_header_sectionClicked)
mode = QAbstractItemView.SingleSelection
self.table.setSelectionMode(mode)
self.grid.addWidget(self.table, 2, 0, 10, 10)
self.filter_lbl = QLabel("Filter:", self)
self.grid.addWidget(self.filter_lbl, 1, 2)
self.filter_entry = QLineEdit(self)
self.grid.addWidget(self.filter_entry, 1, 3)
self.filter_entry.textChanged.connect(self.on_filter_entry_textChanged)
self.filter_text = ""
self.filter_cb = QComboBox(self)
self.grid.addWidget(self.filter_cb, 1, 4)
self.filter_cb.currentIndexChanged.connect(self.on_filter_cb_IndexChanged)
self.filter_btn = QPushButton("Filter!", self)
self.grid.addWidget(self.filter_btn, 1, 5)
self.filter_btn.clicked.connect(self.on_filter_btn_clicked)
self.unfilter_btn = QPushButton("Remove Filter", self)
self.grid.addWidget(self.unfilter_btn, 1, 6)
self.unfilter_btn.clicked.connect(self.on_actionAll_triggered)
self.log.debug("\t=> Done!")
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)
#.........这里部分代码省略.........