如何在QWS上更改光标形状?

时间:2011-12-28 09:17:01

标签: qt qt4 embedded-linux qtembedded

在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?我找不到任何关于它的资源。 感谢您的回复。

1 个答案:

答案 0 :(得分: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();
}

png转换为xpm以获取值不应该太困难。