I have a problem with cursor (Windows XP SP3, Qt 4.7.0 Creator, both debug and release variants):
I don't understand behavior of cursor in this program! When i'm clicking on window (not QLabel area) cursor changes its shape as I expected. When I press mouse button cursor changes to "ClosedHandCursor" and when I released one cursor changes to "OpenHandCursor". But if I moved cursor over QLabel area cursor changes its shape ONLY on QLabel area despite the fact that events "mousePressEvent" and "mouseReleaseEvent" are served - see window title.
Do somebody knows how solve this problem? Thank you.
----------------------------------------------------------
main.cpp
----------------------------------------------------------
#include <QApplication>
#include "Problem.h"
int main(int argc, char *argv[])
{
Problem win;
win.show();
return app.exec();
}
#include <QApplication>
#include "Problem.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Problem win;
win.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
----------------------------------------------------------
problem.h
----------------------------------------------------------
#include <QWidget>
{
public:
Problem();
protected:
};
#include <QWidget>
class Problem : public QWidget
{
public:
Problem();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
};
To copy to clipboard, switch view to plain text mode
----------------------------------------------------------
problem.cpp
----------------------------------------------------------
#include <QtGui>
#include "Problem.h"
Problem::Problem()
{
setWindowTitle(" ? ");
setGeometry(50,50,500,300);
setCursor(Qt::OpenHandCursor);
Label->setFrameStyle(1);
Label->setGeometry(100,100,200,20);
}
{
setCursor(Qt::ClosedHandCursor);
setWindowTitle(" ClosedHandCursor "));
}
{
setCursor(Qt::OpenHandCursor);
setWindowTitle(" OpenHandCursor "));
}
#include <QtGui>
#include "Problem.h"
Problem::Problem()
{
setWindowTitle(" ? ");
setGeometry(50,50,500,300);
setCursor(Qt::OpenHandCursor);
QLabel *Label = new QLabel("Label area", this);
Label->setFrameStyle(1);
Label->setGeometry(100,100,200,20);
}
void Problem::mousePressEvent(QMouseEvent *event)
{
setCursor(Qt::ClosedHandCursor);
setWindowTitle(" ClosedHandCursor "));
}
void Problem::mouseReleaseEvent(QMouseEvent *event)
{
setCursor(Qt::OpenHandCursor);
setWindowTitle(" OpenHandCursor "));
}
To copy to clipboard, switch view to plain text mode
Bookmarks