Qt应用程序的默认鼠标图标 [英] Default mouse icons for Qt applications

查看:452
本文介绍了Qt应用程序的默认鼠标图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Qt应用程序中设置默认的系统鼠标图标?

How to set default system mouse icons in Qt applications?

据我所知,Qt有一组特殊的光标图标(与操作系统或光标主题附带的光标不同).

From what I know Qt has a special set of cursor icons (that are not the same ones with the cursors that come with the operating system or the cursor theme).

...
<button style="cursor: pointer;">Test mouse cursor</button>
...

以手形鼠标图标为例:

在操作系统级别设置的默认手形光标.

Default hand cursor set at operating system level.


Qt游标-与操作系统游标不同.

Qt cursor - that is not the same with the operating system cursor.

我想使用在操作系统级别设置的鼠标图标主题,而不是使用Qt光标主题.

I want to use the mouse icons theme that is set at operating system level, instead of using Qt cursor theme.

我该怎么做?

推荐答案

但是setOverrideCursor()有一个缺点.正如文档所述:

But setOverrideCursor() has one disadvantage. As documentation said:

将应用程序替代光标设置为光标.

Sets the application override cursor to cursor.

应用程序覆盖游标旨在用于向用户显示应用程序处于特殊状态,例如在操作中可能需要一些时间.

Application override cursors are intended for showing the user that the application is in a special state, for example during an operation that might take some time.

此光标将显示在应用程序的所有小部件中,直到调用restoreOverrideCursor()或另一个setOverrideCursor().

This cursor will be displayed in all the application's widgets until restoreOverrideCursor() or another setOverrideCursor() is called.

应用程序游标存储在内部堆栈中. setOverrideCursor()将光标推到堆栈上,restoreOverrideCursor()将活动光标弹出堆栈. changeOverrideCursor()更改当前活动的应用程序覆盖光标.

Application cursors are stored on an internal stack. setOverrideCursor() pushes the cursor onto the stack, and restoreOverrideCursor() pops the active cursor off the stack. changeOverrideCursor() changes the curently active application override cursor.

每个setOverrideCursor()最终都必须跟随相应的restoreOverrideCursor(),否则堆栈将永远不会被清空.

Every setOverrideCursor() must eventually be followed by a corresponding restoreOverrideCursor(), otherwise the stack will never be emptied.

链接: http://qt-project.org/doc/qt-4.8/qapplication.html#setOverrideCursor

这意味着所有小部件都将具有此光标,并且您无法更改它.所以我有下一个解决方案:

It means that all widgets will have this cursor and you can't change it. So I have next solution:

将光标设置为主窗口,它将是默认光标,但是您可以更改每个所需小部件的光标,但是mainWindow的光标将是默认光标.

Set cursor to your mainwindow, it will be default cursor, but you be able to change cursor of every widget you want, but mainWindow's cursor will be default.

例如:

this->setCursor(QCursor(Qt::PointingHandCursor));//it is default cursor
//qApp->setOverrideCursor(QCursor(Qt::PointingHandCursor));

QPixmap pix("path");
QCursor cur(pix);
ui->textEdit->viewport()->setCursor(cur);//when we hover the textEdit we get this pixmap as cursor.

这篇关于Qt应用程序的默认鼠标图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆