2

在 X11 上,Qt 支持 Xcursor 库,它允许全彩色图标主题。我可以改变光标:

QPixmap cursor(":/res/cursor.png");
mCursor = QCursor(cursor,-1,-1);
setCursor(mCursor);

但是在QWS上,效果很差。我想改变QWS上的光标形状。我无法在 arm 9 系统上安装 libxcursor/xcursor-dev 或类似设备来使用全彩光标。所以我尝试修改Qt-embedded-opensoure。

/* src/corelib/global/qnamespace.h */
    enum CursorShape {
        ArrowCursor,
        UpArrowCursor,
        CrossCursor,
        WaitCursor,
        IBeamCursor,
        SizeVerCursor,
        SizeHorCursor,
        SizeBDiagCursor,
        SizeFDiagCursor,
        SizeAllCursor,
        BlankCursor,
        SplitVCursor,
        SplitHCursor,
        PointingHandCursor,
        ForbiddenCursor,
        WhatsThisCursor,
        BusyCursor,
        OpenHandCursor,
        ClosedHandCursor,
        LastCursor = ClosedHandCursor,
        BitmapCursor = 24,
        CustomCursor = 25 
};

我想用 MyCursor 替换 ArrowCursor。我该如何更换它?是 .png 吗?还是.jpg?我找不到任何关于它的资源。感谢您的任何回复。

4

1 回答 1

2

您可以对其进行硬编码。这是一个完整的程序来演示:

#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QCursor>

static const char *const cursor_xpm[] = {
    "15 15 3 1",
    "   c None",
    ".  c #000000",
    "*  c #aa0000",
    "     .....     ",
    "   ..*****..   ",
    "  .   ***   .  ",
    " .    ***    . ",
    " .    ***    . ",
    ".     ***     .",
    ".    *****    .",
    ".*************.",
    ".    *****    .",
    ".     ***     .",
    " .    ***    . ",
    " .    ***    . ",
    "  .   ***   .  ",
    "   ..*****..   ",
    "     .....     "
};

int main(int argc, char* argv[]){

  QApplication app(argc, argv);
  QCursor myCursor(cursor_xpm);
  QWidget widget;
  widget.setCursor(myCursor);
  widget.show();
  return app.exec();
}

转换pngxpm获取值应该不会太困难。

于 2011-12-29T04:28:53.897 回答