PDA

View Full Version : change cursor



nicky
31st January 2007, 04:01
Hi all~~ a new guy of Qt. :) i got a problem about setCursor~~, when pressing mouse button on a label, the cursor cannot be altered by using the function setCursor. Help me! :)

aamer4yu
31st January 2007, 05:03
and why not ?

Check this code..

#include <QApplication>
#include <QLabel>
#include <QMainWindow>


class CLabel :public QLabel
{
public:
void mousePressEvent ( QMouseEvent * event );
void mouseReleaseEvent ( QMouseEvent * event );
};

void CLabel::mousePressEvent(QMouseEvent * event )
{
setCursor(Qt::CrossCursor);
}

void CLabel::mouseReleaseEvent(QMouseEvent * event )
{
setCursor(Qt::ArrowCursor);
}

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

QMainWindow window;
CLabel label;
window.setCentralWidget(&label);

window.show();

return app.exec();

}

hope this helps

rajesh
31st January 2007, 12:07
nicky,
is your question:
when you move the mouse over label then you want to change cursor and when you move away then cursor come to old style?