2

On X11, Qt supports the Xcursor library, which allows for full color icon themes. I can change the cursor:

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

But on QWS,the effect is very bad.I want to change the cursor shape on QWS. I can't install libxcursor/xcursor-dev or similar on arm 9 systems to use full colour cursors. So I try to modify 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 
};

I want to replace ArrowCursor with MyCursor. How can I replace it ? Is it .png ? or .jpg? I can't find any resources about it. Thanks for any replies.

Carina
  • 2,260
  • 2
  • 20
  • 45

1 Answers1

2

You could hardcode it in. Here is a complete program to demonstrate:

#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();
}

Converting png to xpm to get the values shouldn't be too difficult.

Arlen
  • 6,641
  • 4
  • 29
  • 61
  • Thank you for your reply. But on QWS , the cursor is still not full colour,only white and black, without red (#aa0000). – Carina Dec 29 '11 at 05:58
  • Is everything else black and white too? Could you describe your environment little more? – Arlen Dec 29 '11 at 08:25
  • By "Only black and white" you mean the cursor is the only thing that's black and white? or, do you mean everything in your app is black and white? Could you clarify please. And, what is your actual hardware (device name)? – Arlen Dec 29 '11 at 10:26
  • The cursor is the only thing that's black and white.My app is normal,but cursor not. I used a development board which named Bobo by me. ^.^ ~ I think the black and white cursor and hardware are not related . – Carina Dec 30 '11 at 06:07
  • Well, it's your hardware and/or your environment. Everything is in colour for me when I do `./myapp -qws`. – Arlen Dec 30 '11 at 06:12
  • Your reply is very important to me!It's very helpful! But I am still very confused, what environmental factor affect the cursor color. – Carina Dec 30 '11 at 06:20
  • If something is wrong with your xpm, for example, that could cause the cursor to not display or be missing colours. But, in our case, I don't think that's the issue. have you tried running your app on an non-embedded system to see if the cursor is in colour? Unfortunately, I don't have any experience with embedded systems, so I can't say for sure what could cause the cursor to misbehave. – Arlen Dec 30 '11 at 06:34
  • Thanks.The cursor is in full colour on non-embedded system. – Carina Dec 30 '11 at 06:53