我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用PyQt5.QtCore.Qt.CustomContextMenu()。
def setupUi(self, tab_content): super(GenerateProtocolTab, self).setupUi(tab_content) self._tab_content = tab_content self.loadProtocolButton.clicked.connect(lambda: self._select_protocol()) self.saveButton.clicked.connect(lambda: self._save_protocol()) self.loadColumnButton.clicked.connect(lambda: self._load_column_action()) self.loadGB.clicked.connect(lambda: self._load_g_and_b()) self.clearButton.clicked.connect(self._clear_table) self.protocol_table.setSortingEnabled(True) headers = self.protocol_table.horizontalHeader() headers.setContextMenuPolicy(Qt.CustomContextMenu) headers.customContextMenuRequested.connect(self.show_header_context_menu) headers.setSelectionMode(QAbstractItemView.SingleSelection)
def __init__(self, parent=None): super(VideoList, self).__init__(parent) self.parent = parent self.theme = self.parent.theme self.setMouseTracking(True) self.setDropIndicatorShown(True) self.setFixedWidth(190) self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setContentsMargins(0, 0, 0, 0) self.setItemDelegate(VideoItem(self)) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) self.setUniformItemSizes(True) self.setDragEnabled(True) self.setDragDropMode(QAbstractItemView.InternalMove) self.setContextMenuPolicy(Qt.CustomContextMenu) self.setAlternatingRowColors(True) self.setObjectName('cliplist') self.setStyleSheet('QListView::item { border: none; }') self.opacityEffect = OpacityEffect(0.3) self.opacityEffect.setEnabled(False) self.setGraphicsEffect(self.opacityEffect)
def __init__(self, view): QObject.__init__(self, view) self.view = view self.model = QStandardItemModel() self.view.setModel(self.model) self.nodesets = [] self.server_mgr = None self._nodeset_to_delete = None self.view.header().setSectionResizeMode(1) addNodeSetAction = QAction("Add Reference Node Set", self.model) addNodeSetAction.triggered.connect(self.add_nodeset) self.removeNodeSetAction = QAction("Remove Reference Node Set", self.model) self.removeNodeSetAction.triggered.connect(self.remove_nodeset) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.showContextMenu) self._contextMenu = QMenu() self._contextMenu.addAction(addNodeSetAction) self._contextMenu.addAction(self.removeNodeSetAction)
def setup_context_menu_tree(self): self.ui.treeView.setContextMenuPolicy(Qt.CustomContextMenu) self.ui.treeView.customContextMenuRequested.connect(self._show_context_menu_tree) self._contextMenu = QMenu() # tree view menu self._contextMenu.addAction(self.ui.actionCopy) self._contextMenu.addAction(self.ui.actionPaste) self._contextMenu.addAction(self.ui.actionDelete) self._contextMenu.addSeparator() self._contextMenu.addAction(self.tree_ui.actionReload) self._contextMenu.addSeparator() self._contextMenu.addAction(self.ui.actionAddFolder) self._contextMenu.addAction(self.ui.actionAddObject) self._contextMenu.addAction(self.ui.actionAddVariable) self._contextMenu.addAction(self.ui.actionAddProperty) self._contextMenu.addAction(self.ui.actionAddMethod) self._contextMenu.addAction(self.ui.actionAddObjectType) self._contextMenu.addAction(self.ui.actionAddVariableType) self._contextMenu.addAction(self.ui.actionAddDataType)
def __init__(self, view): QObject.__init__(self, view) self.view = view self.model = QStandardItemModel() self.view.setModel(self.model) delegate = MyDelegate(self.view, self) delegate.error.connect(self.error.emit) self.view.setItemDelegate(delegate) self.node = None self.view.header().setSectionResizeMode(1) self.addNamespaceAction = QAction("Add Namespace", self.model) self.addNamespaceAction.triggered.connect(self.add_namespace) self.removeNamespaceAction = QAction("Remove Namespace", self.model) self.removeNamespaceAction.triggered.connect(self.remove_namespace) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.showContextMenu) self._contextMenu = QMenu() self._contextMenu.addAction(self.addNamespaceAction) self._contextMenu.addAction(self.removeNamespaceAction)
def set_table_widget(self): self.row_count = 30 self.column_count = 30 self.case_data_list = self.case_data_service.get_format_case_data(self.row_count, self.column_count, self.case_id) self.table_widget.setRowCount(self.row_count) self.table_widget.setColumnCount(self.column_count) for row in range(0, self.row_count): for column in range(0, self.column_count): case_data_detail = self.case_data_list[row][column] if type(self.case_data_list[row][column]) == CaseData: self.table_widget.setItem(row, column, QTableWidgetItem(case_data_detail.data)) else: self.table_widget.setItem(row, column, QTableWidgetItem(case_data_detail)) self.table_widget.setEditTriggers(QAbstractItemView.NoEditTriggers) self.table_widget.cellClicked.connect(self.table_widget_clicked) self.table_widget.horizontalHeader().setContextMenuPolicy(Qt.CustomContextMenu) self.table_widget.horizontalHeader().customContextMenuRequested.connect(self.show_contextmenu)
def __init__(self, parent=None): super(MpvWidget, self).__init__(parent) # Make the frame black, so that the video frame # is distinguishable from the rest when no # video is loaded yet self.setStyleSheet("background-color:black;") self.setMouseTracking(True) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.contextMenu) self.cursortimer = QTimer(self) self.cursortimer.setSingleShot(True) self.cursortimer.timeout.connect(hideCursor)
def __init__(self, book): "Book must be an associated notebook that this Browser is 'controlling'" self.nb = book QWidget.__init__(self) self.lo = QVBoxLayout() self.setLayout(self.lo) #SEtup file system model self.files = QFileSystemModel() self.files.setReadOnly(False) self.files.setNameFilters(supportedTypes) if config.notespath: self.files.setRootPath(config.notespath) #Setup the view over that self.fv = CustomTreeView() self.fv.setModel(self.files) self.fv.hideColumn(2) self.fv.hideColumn(3) self.fv.hideColumn(1) self.fv.resizeColumnToContents(0) self.fv.setAutoScroll(True) #We pass it a reference so it can open things in the notebook self.fv.nb=book #I don't know what that line does, but it's important!!!! self.fv.setRootIndex(self.files.setRootPath("/Users")) #self.fv.doubleClicked.connect(self.dblclk) self.fv.expanded.connect(lambda x: self.fv.resizeColumnToContents(0)) self.fv.clicked.connect(lambda x: self.fv.resizeColumnToContents(0)) self.fv.setDragEnabled(True) self.fv.setDragDropMode(QAbstractItemView.DragDrop) self.fv.setAcceptDrops(True) self.lo.addWidget(self.fv) #Credit to vahancho http://stackoverflow.com/questions/22198427/adding-a-right-click-menu-for-specific-items-in-qtreeview self.fv.setContextMenuPolicy(Qt.CustomContextMenu); self.fv.customContextMenuRequested.connect(self.onCustomContextMenu);
def __init__(self, app, container, parent, memo): """ The widget within each tab of TabWindow, a display for new private messages and user input """ super(__class__, self).__init__() self.parent = parent self.names = [] uic.loadUi(app.theme["ui_path"] + "/MemoMessageWidget.ui", self) self.memo = memo self.app = app self.container = container self.names = self.memo.server.members self.memoUsers.setContextMenuPolicy(Qt.CustomContextMenu) self.memoUsers.customContextMenuRequested.connect(self.openMemoMenu) self.messageContext = QAction("MESSAGE") self.messageContext.triggered.connect(self.message_user) self.userLabel.setText(memo.name.join(["::", "::"])) self.sendButton.clicked.connect(self.send) self.userOutput.setReadOnly(True) self.userOutput.setMouseTracking(True) self.userOutput.anchorClicked.connect(self.anchorClicked) self.userOutput.setOpenLinks(False) self.userOutput.document().setDefaultStyleSheet(self.app.theme["styles"]) self.userOutput.setHtml("<body>\n</body>") if not self.memo.permissions_for(self.memo.server.me).send_messages: self.userInput.setReadOnly(True) ensure_future(self.load_emojis()) ensure_future(self.get_logs())
def __init__(self, view, show_timestamps=True): QObject.__init__(self, view) self.view = view self._timestamps = show_timestamps delegate = MyDelegate(self.view, self) delegate.error.connect(self.error.emit) delegate.attr_written.connect(self.attr_written.emit) self.settings = QSettings() self.view.setItemDelegate(delegate) self.model = QStandardItemModel() self.model.setHorizontalHeaderLabels(['Attribute', 'Value', 'DataType']) state = self.settings.value("WindowState/attrs_widget_state", None) if state is not None: self.view.header().restoreState(state) self.view.setModel(self.model) self.current_node = None self.view.header().setSectionResizeMode(0) self.view.header().setStretchLastSection(True) self.view.expanded.connect(self._item_expanded) self.view.collapsed.connect(self._item_collapsed) self.view.setEditTriggers(QAbstractItemView.DoubleClicked) # Context menu self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.showContextMenu) copyaction = QAction("&Copy Value", self.model) copyaction.triggered.connect(self._copy_value) self._contextMenu = QMenu() self._contextMenu.addAction(copyaction)
def __init__(self, view): self.view = view QObject.__init__(self, view) self.model = QStandardItemModel() delegate = MyDelegate(self.view, self) delegate.error.connect(self.error.emit) delegate.reference_changed.connect(self.reference_changed.emit) self.view.setEditTriggers(QAbstractItemView.DoubleClicked) self.view.setModel(self.model) self.view.setItemDelegate(delegate) self.settings = QSettings() self.model.setHorizontalHeaderLabels(['ReferenceType', 'NodeId', "BrowseName", "TypeDefinition"]) state = self.settings.value("WindowState/refs_widget_state", None) if state is not None: self.view.horizontalHeader().restoreState(state) self.view.horizontalHeader().setSectionResizeMode(0) self.view.horizontalHeader().setStretchLastSection(True) self.node = None self.reloadAction = QAction("Reload", self.model) self.reloadAction.triggered.connect(self.reload) self.addRefAction = QAction("Add Reference", self.model) self.addRefAction.triggered.connect(self.add_ref) self.removeRefAction = QAction("Remove Reference", self.model) self.removeRefAction.triggered.connect(self.remove_ref) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.showContextMenu) self._contextMenu = QMenu() self._contextMenu.addAction(self.reloadAction) self._contextMenu.addSeparator() self._contextMenu.addAction(self.addRefAction) self._contextMenu.addAction(self.removeRefAction)
def init_signals(self): if not self.should_show: return super(FIRSTUI.CheckAll, self).init_signals() self.select_highest_ranked.stateChanged.connect(self.select_highest) self.filter_sub_funcs_only.stateChanged.connect(self.filter_only_subs) self.tree_view.clicked.connect(self.tree_clicked) # A reference is needed to the dialog or else it closes quickly # after showing self.history_dialogs = [] self.tree_view.setContextMenuPolicy(Qt.CustomContextMenu) self.tree_view.customContextMenuRequested.connect(self.custom_menu)
def init_signals(self): if self.should_show: super(FIRSTUI.CheckAll, self).init_signals() self.tree_view.clicked.connect(self.tree_clicked) # A reference is needed to the dialog or else it closes quickly # after showing self.history_dialogs = [] self.tree_view.setContextMenuPolicy(Qt.CustomContextMenu) self.tree_view.customContextMenuRequested.connect(self.custom_menu)
def setUi(self): self.temperatureLineEdit.setValidator(QDoubleValidator(self)) self.magneticFieldLineEdit.setValidator(QDoubleValidator(self)) self.e1MinLineEdit.setValidator(QDoubleValidator(self)) self.e1MaxLineEdit.setValidator(QDoubleValidator(self)) self.e1NPointsLineEdit.setValidator(QIntValidator(self)) self.e1LorentzianLineEdit.setValidator(QDoubleValidator(self)) self.e1GaussianLineEdit.setValidator(QDoubleValidator(self)) self.e2MinLineEdit.setValidator(QDoubleValidator(self)) self.e2MaxLineEdit.setValidator(QDoubleValidator(self)) self.e2NPointsLineEdit.setValidator(QIntValidator(self)) self.e2LorentzianLineEdit.setValidator(QDoubleValidator(self)) self.e2GaussianLineEdit.setValidator(QDoubleValidator(self)) self.nPsisLineEdit.setValidator(QIntValidator(self)) self.fkLineEdit.setValidator(QDoubleValidator(self)) self.gkLineEdit.setValidator(QDoubleValidator(self)) self.zetaLineEdit.setValidator(QDoubleValidator(self)) # Create the results model and assign it to the view. self.resultsModel = ListModel() self.resultsView.setModel(self.resultsModel) self.resultsView.setSelectionMode(QAbstractItemView.ExtendedSelection) self.resultsView.selectionModel().selectionChanged.connect( self.selectedCalculationsChanged) # Add a context menu. self.resultsView.setContextMenuPolicy(Qt.CustomContextMenu) self.createResultsContextMenu() self.resultsView.customContextMenuRequested[QPoint].connect( self.showResultsContextMenu) # Enable actions. self.elementComboBox.currentTextChanged.connect(self.resetCalculation) self.chargeComboBox.currentTextChanged.connect(self.resetCalculation) self.symmetryComboBox.currentTextChanged.connect(self.resetCalculation) self.experimentComboBox.currentTextChanged.connect( self.resetCalculation) self.edgeComboBox.currentTextChanged.connect(self.resetCalculation) self.magneticFieldLineEdit.editingFinished.connect( self.updateMagneticField) self.e1GaussianLineEdit.editingFinished.connect(self.updateBroadening) self.e2GaussianLineEdit.editingFinished.connect(self.updateBroadening) self.kinLineEdit.editingFinished.connect(self.updateIncidentWaveVector) self.einLineEdit.editingFinished.connect( self.updateIncidentPolarizationVector) self.nPsisAutoCheckBox.toggled.connect(self.updateNPsisLineEditState) self.fkLineEdit.editingFinished.connect(self.updateScalingFactors) self.gkLineEdit.editingFinished.connect(self.updateScalingFactors) self.zetaLineEdit.editingFinished.connect(self.updateScalingFactors) self.saveInputAsPushButton.clicked.connect(self.saveInputAs) self.calculationPushButton.clicked.connect(self.runCalculation)