def contextEvent(self, event): currentWidget = self.searchResultTableIndexs.get(self.currentName) if not currentWidget: return item = currentWidget.itemAt(currentWidget.mapFromGlobal(QCursor.pos())) self.menu = QMenu(currentWidget) self.menu.addAction(self.actionDownloadSong) try: self.currentIndex = item.row() - 1 # 在索引是最后一行时会获取不到。 except: self.currentIndex = -1 self.menu.exec_(QCursor.pos())
def singsFrameContextMenuEvent(self, event): item = self.detailSings.singsTable.itemAt(self.detailSings.singsTable.mapFromGlobal(QCursor.pos())) self.menu = QMenu(self.detailSings.singsTable) self.menu.addAction(self.actionNextPlay) self.menu.addAction(self.actionDownloadSong) try: self.currentIndex = item.row() - 1 # 在索引是最后一行时会获取不到。 except: self.currentIndex = -1 self.menu.exec_(QCursor.pos())
def mouseReleaseEvent(self, event): # 先进行判断,防止误点将鼠标移开后还是会判断为已经点击的尴尬。 if QCursor.pos() != self.mousePos: return else: self.clicked.emit(self.ids, self.picName)
def mousePressEvent(self, event): # 记录下当前鼠标的位置。 self.mousePos = QCursor.pos()