def mouseReleaseEvent(self, event): """ Обрабатываем нажатие на иконку 'Интересно/Скучно' как нажатие на обычный чекбокс Решение достаточно грубое, но в данной ситуации вполне себе работает. Перехватывать нужно отпускание мыши, потому что в QAbstractItemView редактирование запускается именно по отпусканию. """ if event.pos().x() < settings.entryIconWidth(): item = self.itemAt(event.pos()) item.setSelected(True) rect = self.visualItemRect(item) iconRect = QRect(rect.left(), rect.top(), settings.entryIconWidth(), settings.entryIconHeight()) if iconRect.contains(event.pos()): if item.checkState() == Qt.Checked: item.setCheckState(Qt.Unchecked) else: item.setCheckState(Qt.Checked) else: QListWidget.mousePressEvent(self, event)
def mousePressEvent(self, e): index = self.indexAt(e.pos()) if index.isValid(): item = self.itemAt(e.pos()) if e.button() == Qt.RightButton: self.menu.popup(QCursor.pos()) QListWidget.mousePressEvent(self, e)
def mousePressEvent(self, e): """ Start a drag operation Arguments: e -- a QMouseEvent """ if e.button() == Qt.RightButton: item = self.itemAt(e.pos()) if item == None: return note = item.zoteroItem.get_note() if note != None: self.qnotero.previewNote(note) return QListWidget.mousePressEvent(self, e) qnoteroItem = self.currentItem() if qnoteroItem == None: return if not hasattr(qnoteroItem, "zoteroItem"): return zoteroItem = qnoteroItem.zoteroItem if zoteroItem.fulltext == None: return path = zoteroItem.fulltext.encode("latin-1") tmpName = '%s.pdf' % zoteroItem.filename_format() tmpFile = os.path.join(tempfile.gettempdir(), tmpName) suffix = 1 while os.path.exists(tmpFile): tmpName = '%s-%d.pdf' % (zoteroItem.filename_format(), suffix) tmpFile = os.path.join(tempfile.gettempdir(), tmpName) suffix += 1 try: shutil.copy(path, tmpFile) except: print( "qnoteroResults.mousePressEvent(): failed to copy file, sorry..." ) return print("qnoteroResults.mousePressEvent(): prepare to copy %s" % path) print("qnoteroResults.mousePressEvent(): prepare to copy (tmp) %s" \ % tmpFile) mimeData = QMimeData() mimeData.setUrls([QUrl.fromLocalFile(tmpFile)]) mimeData.setData("text/plain", tmpFile) drag = QDrag(self) drag.setMimeData(mimeData) drag.exec_(Qt.CopyAction)
def mousePressEvent(self, e): """ Start a drag operation Arguments: e -- a QMouseEvent """ if e.button() == Qt.RightButton: item = self.itemAt(e.pos()) if item == None: return note = item.zoteroItem.get_note() if note != None: self.qnotero.previewNote(note) return QListWidget.mousePressEvent(self, e) qnoteroItem = self.currentItem() if qnoteroItem == None: return if not hasattr(qnoteroItem, "zoteroItem"): return zoteroItem = qnoteroItem.zoteroItem if zoteroItem.fulltext == None: return path = zoteroItem.fulltext.encode("latin-1") tmpName = '%s.pdf' % zoteroItem.filename_format() tmpFile = os.path.join(tempfile.gettempdir(), tmpName) suffix = 1 while os.path.exists(tmpFile): tmpName = '%s-%d.pdf' % (zoteroItem.filename_format(), suffix) tmpFile = os.path.join(tempfile.gettempdir(), tmpName) suffix += 1 try: shutil.copy(path, tmpFile) except: print "qnoteroResults.mousePressEvent(): failed to copy file, sorry..." return print "qnoteroResults.mousePressEvent(): prepare to copy %s" % path print "qnoteroResults.mousePressEvent(): prepare to copy (tmp) %s" \ % tmpFile mimeData = QMimeData() mimeData.setUrls([QUrl.fromLocalFile(tmpFile)]) mimeData.setData("text/plain", tmpFile) drag = QDrag(self) drag.setMimeData(mimeData) drag.exec_(Qt.CopyAction)
def _playlistRClick(self, event): event.accept() if event.button() == QtCore.Qt.RightButton: self.playlist.clearSelection() QListWidget.mousePressEvent(self.playlist, event)
def _album_songsRClick(self, event): event.accept() if event.button() == QtCore.Qt.RightButton: self.overlay.album_songs.clearSelection() QListWidget.mousePressEvent(self.overlay.album_songs, event)