Carina
Carina

Reputation: 2260

How can I change the cursor shape on QWS ?

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.

Upvotes: 2

Views: 1198

Answers (1)

Arlen
Arlen

Reputation: 6835

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.

Upvotes: 2

Related Questions