Qt C++中如何改变光标
How to change the cursor in Qt C++
如何将光标更改为本地计算机中的图像?
我已按照本教程进行代码参考:
http://www.newthinktank.com/2018/07/qt-tutorial-5-paint-app/
在您的 .qrc 文件中试试这个:
<RCC>
<qresource prefix="/">
<file>cursors/my_cursor.png</file>
</qresource>
</RCC>
然后这样编程:
QPixmap p = QPixmap(":my_cursor");
QCursor c = QCursor(p, 0, 0);
setCursor(c);
我认为您应该使用 class QCursor,一旦鼠标进入图像内部,您就可以使用函数 setShape() 修改其形状。
如文档所述:
To associate a cursor with a widget, use QWidget::setCursor(). To
associate a cursor with all widgets (normally for a short period of
time), use QGuiApplication::setOverrideCursor().
To set a cursor shape use QCursor::setShape() or use the QCursor
constructor which takes the shape as argument, or you can use one of
the predefined cursors defined in the Qt::CursorShape enum.
您可以 暂时 并在稳定 的基础上更改光标。
稳定方式是指,光标只是按原样设置。
使用 QWidget::setCursor()
。
请注意,应用此对象的对象必须是 QWidget。
临时方式覆盖永久光标。
当你做
QGuiApplication::setOverrideCursor(QCursor(/* your cursor here */));
您将此光标添加到堆栈的顶部。如果放置了多个游标,在弹出它们时,我们会以相反的顺序获取它们。
要弹出一个游标,我们这样做:
QGuiApplication::restoreOverrideCursor();
仅一次更改或来回摆动并不重要,但如果光标有可能堆积,这将很重要。
如何将光标更改为本地计算机中的图像? 我已按照本教程进行代码参考: http://www.newthinktank.com/2018/07/qt-tutorial-5-paint-app/
在您的 .qrc 文件中试试这个:
<RCC>
<qresource prefix="/">
<file>cursors/my_cursor.png</file>
</qresource>
</RCC>
然后这样编程:
QPixmap p = QPixmap(":my_cursor");
QCursor c = QCursor(p, 0, 0);
setCursor(c);
我认为您应该使用 class QCursor,一旦鼠标进入图像内部,您就可以使用函数 setShape() 修改其形状。
如文档所述:
To associate a cursor with a widget, use QWidget::setCursor(). To associate a cursor with all widgets (normally for a short period of time), use QGuiApplication::setOverrideCursor().
To set a cursor shape use QCursor::setShape() or use the QCursor constructor which takes the shape as argument, or you can use one of the predefined cursors defined in the Qt::CursorShape enum.
您可以 暂时 并在稳定 的基础上更改光标。
稳定方式是指,光标只是按原样设置。
使用 QWidget::setCursor()
。
请注意,应用此对象的对象必须是 QWidget。
临时方式覆盖永久光标。
当你做
QGuiApplication::setOverrideCursor(QCursor(/* your cursor here */));
您将此光标添加到堆栈的顶部。如果放置了多个游标,在弹出它们时,我们会以相反的顺序获取它们。
要弹出一个游标,我们这样做:
QGuiApplication::restoreOverrideCursor();
仅一次更改或来回摆动并不重要,但如果光标有可能堆积,这将很重要。