拖出应用程序时如何覆盖光标?

时间:2012-09-27 09:00:10

标签: qt drag-and-drop cursor

当我拖放到主窗口外时,是否可以覆盖标准“停止”(交叉圆圈)光标?我有非常简单的代码,这对我来说已经足够了。我将PushButton拖到主窗口之外,然后在释放鼠标按钮上,我获得释放鼠标的窗口。就像一个标准的Windows间谍。那么如何在主窗口外覆盖光标呢?

class DDButton : public QPushButton
{
    Q_OBJECT
public:
    explicit DDButton(QWidget *parent = 0);

signals:

public slots:

private:
    void mousePressEvent(QMouseEvent *event);
};

CPP

void DDButton::mousePressEvent(QMouseEvent *event)
{
     if (event->button() == Qt::LeftButton) {

         QDrag *drag = new QDrag(this);
         QMimeData *mimeData = new QMimeData;

         drag->setMimeData(mimeData);
         drag->setPixmap(cursor.pixmap());
         drag->setHotSpot(QPoint(0,0));

         //This block not working
         QCursor cursor(Qt::OpenHandCursor);
         drag->setDragCursor(cursor.pixmap(), Qt::IgnoreAction);

         Qt::DropAction dropAction = drag->exec();

         //Do something
         qDebug()<<"Press";
     }
}

0 个答案:

没有答案