def __contextual_menu(self, point): index = self.item_tree_view.indexAt(point) src_index = index.model().mapToSource(index) self.selected_item = src_index.internalPointer() global_pos = self.item_tree_view.header().mapToGlobal(point) action = QAction(self) action.setText("Mark for Recording") action.setCheckable(True) if self.selected_item.marked: action.setChecked(True) else: action.setChecked(False) action.triggered.connect(self.__item_marked) menu = QMenu() menu.addAction(action) menu.exec_(global_pos)
def eventFilter(self, obj, event): if event.type() in self._event_callbacks: ret_val = self._event_callbacks[event.type()](obj, event) if ret_val is not None: return ret_val if event.type() == event.ContextMenu and obj == self.title_label: menu = QMenu(self) rename_action = menu.addAction(self.tr('Rename dock widget')) hide_action = QAction("Hide title bar", self) hide_action.setCheckable(True) hide_action.setChecked(self.hide_title_bar) if self._dock_widget.features() & QDockWidget.DockWidgetFloatable and \ self._dock_widget.features() & QDockWidget.DockWidgetMovable: menu.addAction(hide_action) action = menu.exec_(self.mapToGlobal(event.pos())) if action == rename_action: self.title_label.hide() self.title_edit.setText(self.title_label.text()) self.title_edit.show() self.title_edit.setFocus() if action == hide_action: self.hide_title_bar = not self.hide_title_bar return True return QObject.eventFilter(self, obj, event)