class DragLabel(QtGui.QLabel): def __init__(self, parent): super(DragLabel, self).__init__(parent) self.offset = 0 self.icon_path = "" self.move_icon = None self.double_click_func = None self.ecu_key = None self.selected = False self.contextMenu = QMenu(str("Context menu"), self); self.env_view = None @try_ex def set_doubleclick_func(self, func): self.double_click_func = func @try_ex def enterEvent(self, *args, **kwargs): self.setCursor(Qt.OpenHandCursor) if not self.selected: self.setStyleSheet('QLabel { border: 2px solid red; padding: 0px; border-radius: 15px} ') @try_ex def leaveEvent(self, *args, **kwargs): if not self.selected: self.setStyleSheet('QLabel {border: 0px solid red;border-radius: 15px;}') @try_ex def mousePressEvent(self, e): if e.button() == QtCore.Qt.LeftButton: self.setCursor(Qt.ClosedHandCursor) self.offset = e.pos() if e.modifiers() == Qt.ControlModifier: if self.selected: self.setStyleSheet('QLabel {border: 0px solid red;border-radius: 15px;}') self.selected = False try: DragSelection().selected.remove(self) except: pass else: self.setStyleSheet('QLabel { border: 2px solid red; background: darkred; padding: 0px; border-radius: 15px} ') self.selected = True DragSelection().selected.append(self) if e.button() == QtCore.Qt.RightButton: DragSelection().clicked = self pop = e.pos() + self.parent().pos() self.contextMenu.exec(self.mapToParent(pop)); # HERE POSITION @try_ex def set_context_menu_actions(self, actions): try: self.context_actions = actions for action in self.context_actions: if action not in self.contextMenu.children(): self.contextMenu.addAction(action) except: pass @try_ex def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.setCursor(Qt.ArrowCursor); cur_pos = e.pos() - self.offset @try_ex def mouseMoveEvent(self, event): self.move(self.mapToParent(event.pos() - self.offset)); a = self.env_view GBuilder().update_connected(a, None, None, self.env_view.selected_env) print("Move") @try_ex def mouseDoubleClickEvent(self, e): try: self.double_click_func(e.pos() - self.offset, self.ecu_key, self) except: ECULogger().log_traceback()