本文整理汇总了Python中PyQt4.QtGui.QDrag.setHotSpot方法的典型用法代码示例。如果您正苦于以下问题:Python QDrag.setHotSpot方法的具体用法?Python QDrag.setHotSpot怎么用?Python QDrag.setHotSpot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QDrag
的用法示例。
在下文中一共展示了QDrag.setHotSpot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mousePressEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mousePressEvent( self, event ):
# handle an internal move
from PyQt4.QtCore import Qt
# start a drag event
if ( event.button() == Qt.LeftButton and self.dragDropRect().contains( event.pos() ) ):
from PyQt4.QtCore import QMimeData
from PyQt4.QtGui import QDrag, QPixmap
# create the pixmap
pixmap = QPixmap.grabWidget( self, self.rect() )
# create the mimedata
mimeData = QMimeData()
mimeData.setText( 'ItemTitle::%s' % (self.title()) )
# create the drag
drag = QDrag(self)
drag.setMimeData( mimeData )
drag.setPixmap( pixmap )
drag.setHotSpot( event.pos() )
if ( not drag.exec_() ):
self._accordianWidget.emitItemDragFailed(self)
event.accept()
# determine if the expand/collapse should occur
elif ( event.button() == Qt.LeftButton and self.expandCollapseRect().contains( event.pos() ) ):
self._clicked = True
event.accept()
else:
event.ignore()
示例2: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self,event):
#if the left mouse button is used
if event.buttons() == Qt.LeftButton:
data = QByteArray()
mime_data = QMimeData()
mime_data.setData(self.mimetext,data)
drag = QDrag(self)
drag.setMimeData(mime_data)
drag.setHotSpot(self.rect().topLeft()) #where do we drag from
drop_action = drag.start(Qt.MoveAction) #drag starts
示例3: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self, event):
if event.buttons() != Qt.RightButton:
return
mimeData = QMimeData()
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(event.pos() - self.rect().topLeft())
dropAction = drag.start(Qt.MoveAction)
if dropAction == Qt.MoveAction:
self.close()
示例4: startDrag
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def startDrag(self):
image = self.image()
data = QMimeData()
data.setImageData(image)
drag = QDrag(self)
drag.setMimeData(data)
if max(image.width(), image.height()) > 256:
image = image.scaled(QSize(256, 256), Qt.KeepAspectRatio, Qt.SmoothTransformation)
pixmap = QPixmap.fromImage(image)
drag.setPixmap(pixmap)
drag.setHotSpot(pixmap.rect().center())
drag.exec_(Qt.CopyAction)
示例5: drag
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def drag(self, tile=None, meld=None):
"""returns a drag object"""
drag = QDrag(self)
mimeData = MimeData(tile, meld)
drag.setMimeData(mimeData)
tile = tile or meld[0]
graphics = tile.graphics
tRect = graphics.boundingRect()
tRect = self.viewportTransform().mapRect(tRect)
pmapSize = QSize(tRect.width() * graphics.scale(), tRect.height() * graphics.scale())
pMap = graphics.pixmapFromSvg(pmapSize)
drag.setPixmap(pMap)
drag.setHotSpot(QPoint(pMap.width()/2, pMap.height()/2))
return drag
示例6: startDrag
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def startDrag(self, mainwin, ev):
d = mainwin.currentDocument()
if not d:
return
url = d.url()
if url.isEmpty():
return
drag = QDrag(mainwin)
data = QMimeData()
data.setUrls([url])
drag.setMimeData(data)
pixmap = mainwin.style().standardPixmap(QStyle.SP_FileIcon, 0, mainwin)
hotspot = QPoint(pixmap.width() - 5, 5)
drag.setPixmap(pixmap)
drag.setHotSpot(hotspot)
drag.start(Qt.LinkAction | Qt.CopyAction)
示例7: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self, event):
if event.buttons() != Qt.LeftButton:
return
mimeData = QMimeData()
if self.pos == -1:
return
mimeData.setData("splitter/fragment", QByteArray.number(self.pos))
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(event.pos() - self.rect().topLeft())
dropAction = drag.start(Qt.MoveAction)
if dropAction == Qt.MoveAction:
self.close()
示例8: startDrag
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def startDrag(self):
image = self.image()
data = QMimeData()
data.setImageData(image)
drag = QDrag(self)
drag.setMimeData(data)
if max(image.width(), image.height()) > 256:
image = image.scaled(QSize(256, 256), Qt.KeepAspectRatio, Qt.SmoothTransformation)
p = QPainter()
p.begin(image)
p.setCompositionMode(QPainter.CompositionMode_DestinationIn)
p.fillRect(image.rect(), QColor(0, 0, 0, 160))
p.end()
pixmap = QPixmap.fromImage(image)
drag.setPixmap(pixmap)
drag.setHotSpot(pixmap.rect().center())
drag.exec_(Qt.CopyAction)
示例9: startDrag
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def startDrag(self, supportedActions):
""" Overwritten function of QTreeWidget.
This function creates a QDrag object representing the selected element of this TreeWidget.
"""
logging.debug(self.__class__.__name__ +": startDrag()")
indexes = self.selectedIndexes()
if len(indexes) > 0:
data = self.model().mimeData(indexes)
if not data:
return
drag = QDrag(self)
drag.setMimeData(data)
if self.model().data(indexes[0], Qt.DecorationRole).type() == QVariant.Icon:
icon = QIcon(self.model().data(indexes[0], Qt.DecorationRole))
drag.setPixmap(icon.pixmap(QSize(50, 50)))
drag.setHotSpot(QPoint(drag.pixmap().width()/2, drag.pixmap().height()/2)) # center icon in respect to cursor
defaultDropAction = Qt.IgnoreAction
drag.exec_(supportedActions, defaultDropAction)
示例10: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self, e):
if self.drag_start is None:
pass
x = e.x() - self.drag_start.x()
y = e.y() - self.drag_start.y()
dist = QApplication.startDragDistance()
if not self.draggable or x > dist or y > dist:
return
drag = QDrag(self)
mime = QMimeData()
mime.setText(self.__class__.__name__)
mime.part = self
drag.setMimeData(mime)
pixmap = QPixmap.grabWidget(self)
pixmap.setAlphaChannel(pixmap)
drag.setPixmap(pixmap)
drag.setHotSpot(QPoint(drag.pixmap().width() / 2,
drag.pixmap().height()))
drag.start(Qt.CopyAction)
示例11: startDrag
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def startDrag(self, drop_actions):
selected_doc_items = self.selectedItems()
data = QByteArray()
stream = QDataStream(data, QIODevice.WriteOnly)
for doc_item in selected_doc_items:
stream.writeQString(doc_item.text() + ":" + doc_item.get_full_name())
mimeData = QMimeData()
mimeData.setData("application/x-doc-list", data)
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(QPoint(0, 0))
if drag.start(Qt.MoveAction) == Qt.MoveAction:
docs = []
for doc_item in selected_doc_items:
# self.takeItem(self.row(doc_item))
docs.append(doc_item.text())
self.emit(SIGNAL("removeDocs"), docs)
示例12: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self, e):
if self.drag_start is None:
pass
x = e.x() - self.drag_start[0]
y = e.y() - self.drag_start[1]
dist = QApplication.startDragDistance()
if (self.draggable is False) or (abs(x) < dist and abs(y) < dist):
return
drag = QDrag(self)
mime = QMimeData()
mime.setText(self.__class__.__name__)
mime.part = self
drag.setMimeData(mime)
pixmap = QPixmap.grabWidget(self)
pixmap.setAlphaChannel(pixmap)
drag.setPixmap(pixmap)
drag.setHotSpot(QPoint(drag.pixmap().width() / 2,
drag.pixmap().height()))
self.dragging = True
drag.start(Qt.CopyAction)
示例13: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self, event):
drag = QDrag(event.widget())
data = QMimeData()
data.setText(self.commit.name())
drag.setMimeData(data)
#data.setColorData(GREEN)
pixmap = QPixmap(COMMIT_WIDTH, COMMIT_HEIGHT)
pixmap.fill(WHITE)
painter = QPainter(pixmap)
painter.translate(0, 0)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
painter.setBrush(QBrush(self.color))
painter.drawPath(self.setup_display(0, 0))
painter.end()
pixmap.setMask(pixmap.createHeuristicMask())
drag.setPixmap(pixmap)
drag.setHotSpot(QPoint(0, 0))
drag.start()
示例14: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self, event):
if not (event.buttons() and Qt.LeftButton):
return
currentItem = self.currentItem()
if(currentItem.isFile()):
if(currentItem.isPic()):
currentItemName = self.currentItem().getPath()
data = QByteArray()
stream = QDataStream(data, QIODevice.WriteOnly)
stream.writeQString(currentItemName)
icon = Icons.image
pixmap = icon.pixmap(64, 64)
mimeData = QMimeData()
mimeData.setText(currentItemName)
mimeData.setData('application/x-item', data)
drag = QDrag(self)
drag.setPixmap(pixmap)
drag.setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2))
drag.setMimeData(mimeData)
dropAction = drag.start(Qt.CopyAction)
示例15: mouseMoveEvent
# 需要导入模块: from PyQt4.QtGui import QDrag [as 别名]
# 或者: from PyQt4.QtGui.QDrag import setHotSpot [as 别名]
def mouseMoveEvent(self, e):
# Chequear que se esté presionando el botón izquierdo
if e.buttons() != Qt.LeftButton:
return
# posicion del click dentro del gmod
mimeData = QMimeData()
pixmap = QPixmap.grabWidget(self)
painter = QPainter(pixmap)
painter.setCompositionMode(painter.CompositionMode_DestinationIn)
painter.fillRect(pixmap.rect(), QColor(0, 0, 0, 127))
painter.end()
drag = QDrag(self)
# escribir el MimeData
drag.setMimeData(mimeData)
# establecer el Pixmap
drag.setPixmap(pixmap)
# posicionar correctamente el pixmap
drag.setHotSpot(e.pos())
drag.exec_(Qt.MoveAction)