3

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

标题

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";
     }
}
4

0 回答 0