在拖动过程中更改鼠标指针

时间:2013-02-01 07:42:27

标签: python pyqt4 mouse-pointer

如何在PyQt4中拖动时更改鼠标指针/光标(我想在我的小部件的左侧有一个鼠标指针,在右侧部分有另一个指针):

from PyQt4 import QtGui, QtCore
class Button(QtGui.QPushButton):

    def mousePressEvent(self, event):
        mimedata = QtCore.QMimeData()
        self.drag = QtGui.QDrag(self)
        self.drag.setMimeData(mimedata)
        self.drag.start(QtCore.Qt.CopyAction)


class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.setAcceptDrops(True)
        self.button = Button("Drag me", self)
        self.setGeometry(300, 300, 300, 150)

    def dragEnterEvent(self, e):
        e.accept()

    def dragMoveEvent(self, e):
        pm = QtGui.QPixmap(32,32)

        if e.pos().x()<150:
            pm.fill(QtCore.Qt.blue)    
            self.button.drag.setDragCursor(pm,QtCore.Qt.CopyAction) #Not working
        else:
            pm.fill(QtCore.Qt.red)    
            self.button.drag.setDragCursor(pm,QtCore.Qt.MoveAction) #Not working

app = QtGui.QApplication([])
ex = Example()
ex.show()
app.exec_()  

但是,此代码不会更改鼠标光标。

提前致谢 MADS

0 个答案:

没有答案