def enterEvent(self, event): pos = QCursor().pos() self.btnInfoWidget = BtnInfoWidget(self.path, self.type, self.name) self.btnInfoWidget.move(pos.x() + 50, pos.y() + 50) self.btnInfoWidget.move(self.width() + self.geometry().x() + self.parent().parent().geometry().x(), \ self.height() + self.geometry().y() +self.parent().parent().geometry().y()) self.btnInfoWidget.show() super(btnWin, self).enterEvent(event)
def wrapper(*args, **kwargs): cursor = QCursor(Qt.ArrowCursor) QApplication.setOverrideCursor(cursor) try: return fn(*args, **kwargs) finally: QApplication.restoreOverrideCursor()
def mousePressEvent(self, event): """ Override the behaviour when the mouse is pressed """ self._drag_initiated = False self._drag_dropped_pos = QPoint() if event.button() == Qt.LeftButton and event.modifiers( ) == Qt.ControlModifier: self._drag_start_pos = event.pos() # Get mouse position and store the area rectangle of the selected tab pos = event.pos() self._select_tab_index = self.tabAt(pos) rect = self.tabRect(self._select_tab_index) # Store a pixmap of the selected tab and a pixmap of the close hand cursor image # After that we draw the tab and also the hand cursor in the middle of the tab pixmap = QPixmap.grabWidget(self, rect) painter = QPainter(pixmap) cursor_pm = QPixmap(':/icons/close_hand_cursor.png') cursor_pos = QPoint(*map(lambda x, y: (x - y) * 0.5, rect.size().toTuple(), cursor_pm.size().toTuple())) painter.drawPixmap(cursor_pos, cursor_pm) painter.end() # Update cursor cursor = QCursor(pixmap) self.setCursor(cursor) super(TearOffTabBar, self).mousePressEvent(event)
def eventFilter(self, obj, event): if event.type() == QEvent.Leave: if obj == self._current_widget: if self._temp_tooltip is not None: self._current_widget.setToolTip(self._temp_tooltip) self._temp_tooltip = None self._current_widget = None pos = QCursor.pos() widget_under_cursor = QApplication.widgetAt(pos) # if not widget_under_cursor or widget_under_cursor.objectName() == '': if not widget_under_cursor: self._current_tooltip.hide() return super(ToolsetHelpEvent, self).eventFilter(obj, event) if self._help_mode: self._current_tooltip.move(pos.x() + 15, pos.y()) if self._current_widget != widget_under_cursor: self._current_widget = widget_under_cursor tooltip_data = self._current_widget.property('tooltip_help') self._temp_tooltip = self._current_widget.toolTip() self._current_widget.setToolTip('') self._current_tooltip.update_tooltip(tooltip_data) else: self._current_tooltip.hide() return super(ToolsetHelpEvent, self).eventFilter(obj, event)
def __init__(self, widget, width=450, height=50, icon_size=40, parent=None, show_on_initialize=False, stylesheet='', popup_release=Qt.Key_Control, show_at_cursor=True): self._tooltip_icon = None self._widget = widget self._icon_color = self.ETT_ICON_COLOR self._theme_color = self.ETT_THEME_COLOR self._link_color = self.ETT_LINK_COLOR self._popup_key = popup_release self._icon_size = icon_size self._font = QFont('sans') self._title_font = QFont('sans') super(ExpandedTooltipPopup, self).__init__(width=width, height=height, show_on_initialize=show_on_initialize, parent=parent) if stylesheet != '': self.setStyleSheet(stylesheet) if show_at_cursor: self.move(QCursor.pos()) self.setStyle(self.style())
def show_context_menu(self): """ Creates and shows the context menu for the search widget :return: QAction """ menu = QMenu(self) standard_menu = self.createStandardContextMenu() standard_menu.setTitle('Edit') menu.addMenu(standard_menu) sub_menu = QMenu(menu) sub_menu.setTitle('Space Operator') menu.addMenu(sub_menu) or_action = QAction('OR', menu) or_action.setCheckable(True) or_callback = partial(self.set_space_operator, 'or') or_action.triggered.connect(or_callback) if self.space_operator() == 'or': or_action.setChecked(True) sub_menu.addAction(or_action) and_action = QAction('AND', menu) and_action.setCheckable(True) and_callback = partial(self.set_space_operator, 'and') and_action.triggered.connect(and_callback) if self.space_operator() == 'and': and_action.setChecked(True) sub_menu.addAction(and_action) action = menu.exec_(QCursor.pos()) return action
def _on_show_menu(self): """ Internal callback that shows field menu using the actions from the data """ menu = QMenu(self) actions = self.data().get('actions', list()) for action in actions: name = action.get('name', 'No name found') enabled = action.get('enabled', True) callback = action.get('callback') fn = partial(self._action_callback, callback) action = menu.addAction(name) action.setEnabled(enabled) action.triggered.connect(fn) point = QCursor.pos() point.setX(point.x() + 3) point.setY(point.y() + 3) self._action_result = None menu.exec_(point) if self._action_result is not None: self.set_value(self._action_result)
def _on_window_resized(self): """ Internal function that resizes the frame based on the mouse position and the current direction """ pos = QCursor.pos() new_geo = self.window().frameGeometry() min_width = self.window().minimumSize().width() min_height = self.window().minimumSize().height() if self._direction & ResizeDirection.Left == ResizeDirection.Left: left = new_geo.left() new_geo.setLeft(pos.x() - self._widget_mouse_pos.x()) if new_geo.width() <= min_width: new_geo.setLeft(left) if self._direction & ResizeDirection.Top == ResizeDirection.Top: top = new_geo.top() new_geo.setTop(pos.y() - self._widget_mouse_pos.y()) if new_geo.height() <= min_height: new_geo.setTop(top) if self._direction & ResizeDirection.Right == ResizeDirection.Right: new_geo.setRight(pos.x() + (self.minimumSize().width() - self._widget_mouse_pos.x())) if self._direction & ResizeDirection.Bottom == ResizeDirection.Bottom: new_geo.setBottom(pos.y() + (self.minimumSize().height() - self._widget_mouse_pos.y())) x = new_geo.x() y = new_geo.y() w = max(new_geo.width(), min_width) h = max(new_geo.height(), min_height) self.window().setGeometry(x, y, w, h)
def ExampleMenu_Execute(): """a simple example showing the use of a qmenu""" sianchor = Application.getQtSoftimageAnchor() sianchor = Qt.wrapinstance( long(sianchor), QWidget ) menu = ExampleMenu( sianchor ) # notice the use of QCursor and exec_ call menu.exec_(QCursor.pos())
def ExampleMenu_Execute(): """a simple example showing the use of a qmenu""" sianchor = Application.getQtSoftimageAnchor() sianchor = Qt.wrapinstance(long(sianchor), QWidget) menu = ExampleMenu(sianchor) # notice the use of QCursor and exec_ call menu.exec_(QCursor.pos())
def showContextMenu(self, pos): self.row = self.propertiesTableView.indexAt(pos).row() self.menu = QMenu(self) deleteRowAction = QAction('Delete', self) deleteRowAction.triggered.connect(self.deleteRow) self.menu.addAction(deleteRowAction) # add other required actions self.menu.popup(QCursor.pos())
def doDrag(self, o, e): if self._dragType == self.DRAG_HORIZONTAL: delta = e.pos().x() - self._lastPos.x() else: delta = self._lastPos.y() - e.pos().y() self._leftover += delta self._lastPos = e.pos() count = int(self._leftover / self.dragSensitivity) if count: mul = 1.0 if e.modifiers() & self.fastModifier: mul = self.fastMultiplier elif e.modifiers() & self.slowModifier: mul = 1.0 / self.slowDivisor self.dragTick.emit(count, mul) self._leftover %= self.dragSensitivity if self.cursorLock: QCursor.setPos(self.mapToGlobal(self._dragStart)) self._lastPos = self._dragStart else: r = self._screen b = self.wrapBoundary p = o.mapToGlobal(e.pos()) # when wrapping move to the other side in by 2*boundary # so we don't loop the wrapping if p.x() > r.right() - b: p.setX(r.left() + 2 * b) if p.x() < r.left() + b: p.setX(r.right() - 2 * b) if p.y() > r.bottom() - b: p.setY(r.top() + 2 * b) if p.y() < r.top() + b: p.setY(r.bottom() - 2 * b) if p != e.globalPos(): QCursor.setPos(p) self._lastPos = self.parent().mapFromGlobal(p) self._leftover = 0
def cursor_location(self): pos = self.mapFromGlobal(QCursor.pos()) for drop_area, widget in self._widgets.items(): if drop_area in self._overlay.allowed_areas(): if widget: if widget.isVisible() and widget.geometry().contains(pos): return drop_area return DropArea.InvalidDropArea
def mouseMoveEvent(self, event): """ Override the behaviour when the mouse is moved Doing this we avoid that the tab is moved when tearing off the tab """ if self._select_tab_index < -1: pass else: if event.modifiers() == Qt.ControlModifier: self.setCursor(Qt.OpenHandCursor) else: self.setCursor(Qt.ArrowCursor) if not event.buttons() == Qt.LeftButton: return if not self._drag_start_pos.isNull() and ( event.pos() - self._drag_start_pos ).manhattanLength() < QApplication.startDragDistance(): self._drag_initiated = True if (event.buttons() == Qt.LeftButton ) and self._drag_initiated and not self.geometry().contains( event.pos()): finish_move_event = QMouseEvent(QEvent.MouseMove, event.pos(), Qt.NoButton, Qt.NoButton, Qt.NoModifier) super(TearOffTabBar, self).mouseMoveEvent(finish_move_event) drag = QDrag(self) mime_data = QMimeData() mime_data.setData('action', 'application/tab-detach') drag.setMimeData(mime_data) rect = self.tabRect(self.tabAt(event.pos())) pixmap_big = QPixmap.grabWidget( self.parentWidget().currentWidget()).scaled( 640, 480, Qt.KeepAspectRatio) drag.setPixmap(pixmap_big) drag.setDragCursor(QPixmap(), Qt.LinkAction) dragged = drag.exec_(Qt.MoveAction) if dragged == Qt.IgnoreAction: # moved outside of tab widget event.accept() self.tabDetached.emit(self.tabAt(self._drag_start_pos), QCursor.pos()) elif dragged == Qt.MoveAction: # moved inside of tab widget if not self._drag_dropped_pos.isNull(): event.accept() self.tabMoved.emit(self.tabAt(self._drag_start_pos), self.tabAt(self._drag_dropped_pos)) self._drag_dropped_pos = QPoint() else: super(TearOffTabBar, self).mouseMoveEvent(event)
def _on_show_settings_menu(self): settings_menu = menu.Menu(self) self.settingsMenuRequested.emit(settings_menu) self._create_settings_menu(settings_menu) point = QCursor.pos() point.setX(point.x() + 3) point.setY(point.y() + 3) settings_menu.exec_(point) settings_menu.close()
def _on_open_menu(self): """ Internal function that is called when the user opens the context menu of the tab menu bar :param pos: QPos """ menu = QMenu(self) menu.addAction( QAction('Rename Current Tab', self, triggered=self._on_rename_tab)) menu.exec_(QCursor.pos())
def contextMenuEvent(self, event): """ Overrides base contextMenuEvent function Shows context menu for this widget :param event: QEvent """ menu = self.create_context_menu() point = QCursor.pos() return menu.exec_(point)
def show(self, point=None): """ Overrides base QMenu show function :param point: QPoint """ self.clear() group_by = self.library().group_by() if group_by: current_field = group_by[0].split(':')[0] current_order = 'dsc' if 'dsc' in group_by[0] else 'asc' else: current_field = '' current_order = '' separator_action = action.SeparatorAction('Group By', self) self.addAction(separator_action) none_action = self.addAction('None') none_action.setCheckable(True) none_callback = partial(self.set_group_by, None, None) none_action.triggered.connect(none_callback) if not current_field: none_action.setChecked(True) fields = self.library().fields() for field in fields: if not field.get('groupable'): continue name = field.get('name') field_action = self.addAction(name.title()) field_action.setCheckable(True) field_action.setChecked(bool(current_field == name)) field_callback = partial(self.set_group_by, name, current_order) field_action.triggered.connect(field_callback) group_order_action = action.SeparatorAction('Group Order', self) self.addAction(group_order_action) ascending_action = self.addAction('Ascending') ascending_action.setCheckable(True) ascending_action.setChecked(bool(current_order == 'asc')) ascending_callback = partial(self.set_group_by, current_field, 'asc') ascending_action.triggered.connect(ascending_callback) descending_action = self.addAction('Descending') descending_action.setCheckable(True) descending_action.setChecked(bool(current_order == 'dsc')) descending_callback = partial(self.set_group_by, current_field, 'dsc') descending_action.triggered.connect(descending_callback) point = point or QCursor.pos() self.exec_(point)
def handlePopupMenu(self): """ Called when user right-clicks on a trace """ menu = QMenu() selected = self.selectedDataNames() if len(selected) != 0: menu.addAction(self.actionDeleteTrace) menu.exec_(QCursor.pos())
def keyPressEvent(self, event): if event.key() == self._tt_key: pos = self.mapFromGlobal(QCursor.pos()) action = self.actionAt(pos) if tooltips.has_expanded_tooltips(action): self._popup_tooltip = tooltips.ExpandedTooltipPopup( widget=action, icon_size=qtutils.dpi_scale(40), popup_release=self._tt_key) self._tt_key_pressed = True super(BaseMenuButton.SearchMenu, self).keyPressEvent(event)
def show_sets_menu(cls, path, **kwargs): """ Shows selection set menu at the current cursor position :param path: str :param kwargs: dict """ menu = cls.from_path(path, **kwargs) pos = QCursor.pos() return menu.exec_(pos)
def show_selection_sets_menu(self, **kwargs): """ Shows the selection sets menu for this item at the current cursor position :param kwargs: dict :return: QAction """ menu = self._create_selection_sets_menu(**kwargs) position = QCursor.pos() return menu.exec_(position)
def _on_show_selection_sets_menu(self): """ Internal callback function that shows the selection sets menu for the current folder path """ path = self.folder_path() position = QCursor.pos() library_window = self.library_window() menu = sets.SetsMenu.from_path(path, library_window=library_window) menu.exec_(position)
def isFocusWidget(): """ return true if the global qApp has any focused widgets """ focus = False if QApplication.instance(): if QApplication.instance().focusWidget(): window = QApplication.instance().focusWidget().window() geom = window.geometry() focus = geom.contains(QCursor.pos()) return focus
def isFocusWidget(): """ return true if the global qApp has any focused widgets """ focus = False if QApplication.instance(): if QApplication.instance().focusWidget(): window = QApplication.instance().focusWidget().window() geom = window.geometry() focus = not window.isMinimized() and geom.contains(QCursor.pos()) return focus
def _on_show_menu(self): """ Internal callback function that is called when menu button is clicked byu the user :return: QAction """ menu = QMenu(self) self._item_view.context_edit_menu(menu) point = QCursor.pos() point.setX(point.x() + 3) point.setY(point.y() + 3) return menu.exec_(point)
def _on_show_menu(self): """ Internal callback function triggered when item menu should be opened :return: QAction """ menu = QMenu(self) self.item().context_edit_menu(menu) point = QCursor.pos() point.setX(point.x() + 3) point.setY(point.y() + 3) return menu.exec_(point)
def handlePopupMenu(self): """ Called when user right-clicks on the sources tree """ menu = QMenu() menu.addAction(self.actionAdd) selected = self.main.treeView.selectedItems() if len(selected) != 0: if 'config' in selected[0].source.__dict__: menu.addAction(self.actionConfig) menu.addAction(self.actionDelete) menu.exec_(QCursor.pos())
def show_header_menu(self, pos): """ Creates and show the header menu at the cursor position :param pos: QPoint :return: QMenu """ header = self.header() column = header.logicalIndexAt(pos) menu = self._create_header_menu(column) menu.addSeparator() sub_menu = self._create_hide_column_menu() menu.addMenu(sub_menu) menu.exec_(QCursor.pos())
def handlePopupMenu(self): """ Called when user right-clicks on the sources tree """ menu = QMenu() menu.addAction(self.actionAdd) selected = self.main.treeView.selectedItems() if len(selected) != 0: if "config" in selected[0].source.__dict__: menu.addAction(self.actionConfig) menu.addAction(self.actionDelete) menu.exec_(QCursor.pos())
def __init__(self, properties, headers=None, mode='adri'): """ mode a: allow add mode d: allow delete mode r: allow reorder mode i: force name to be valid identifier """ super().__init__() self.setupUi(self) self.properties = OrderedDict(properties) self.mode = mode # set to cursor position # will place window in current screen, even when cursor at some 'odd location' rect = self.geometry() rect.moveTo(QCursor.pos()) self.setGeometry( rect ) # will place window in current screen, even when at some 'odd location' self.propertiesTableView.setStyle(customStyle()) model = customModel(parent=self.propertiesTableView) self.propertiesTableView.setModel(model) self.row = -1 if 'd' in self.mode: self.propertiesTableView.customContextMenuRequested.connect( self.showContextMenu) if 'a' in self.mode: self.addProperty.clicked.connect(self.addRow) else: self.addProperty.hide() if 'r' in mode: self.propertiesTableView.setDragDropMode( QAbstractItemView.InternalMove) # push buttons signals self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) model.populate(self.properties, headers)
def show(self, point=None): """ Overrides base QMeu show function to allow to show it in a specific position :param point: QPoint or None """ self.clear() field = self._options.get('field') queries = self.library().queries(exclude=self.name()) self._facets = self.library().distinct(field, queries=queries) show_action = action.SeparatorAction('Show {}'.format(field.title()), self) self.addAction(show_action) show_all_action = action.LabelAction('Show All', self) self.addAction(show_all_action) show_all_action.setEnabled(not self.is_show_all_enabled()) show_all_callback = partial(self._on_show_all_action_clicked) show_all_action.triggered.connect(show_all_callback) self.addSeparator() for facet in self._facets: name = facet.get('name', '') checked = self.settings().get(name, True) filter_by_action = FilterByAction(self) filter_by_action.set_facet(facet) filter_by_action.setChecked(checked) self.addAction(filter_by_action) callback = partial(self._on_action_checked, name, not checked) filter_by_action.triggered.connect(callback) point = point or QCursor.pos() self.exec_(point)
def showMenu(self): if QRect(0, 0, self.width(), 20).contains(self.mapFromGlobal(QCursor.pos())): self._expanderWidget.emitItemMenuRequested(self)
def showMenu( self ): if QRect(0, 0, self.width(), 20).contains(self.mapFromGlobal(QCursor.pos())): self._accordianWidget.emitItemMenuRequested(self)