Hi guys, I'm a newbie here. I started playing with Qt only a few weeks ago only in my free time, and now I'm stuck.
I am reimplementing a QMainWindow and some QGraphicsItem.
I have some QPushButtons and a QGraphicsView in the window. I need the cursor shape to change when the user clicks on a QPushButton, and that works properly by calling setCursor(Qt::ForbiddenCursor) and view->viewport()->setCursor(Qt::ForbiddenCursor) (if I call it only on the window, or on the view, the mouse doesn't change when it's on the graphicsView. I need to call it also on the viewport. Why?).
Anyway this works fine if I call the setCursor() on both. Now I need the cursor to go back to normal as soon as the user clicks on a QGraphicsItem. So I override the mousePressEvent in the QGraphicsItem class and do the changes I have to do for my program. At the end of the method I propagate the event to the parent through "QGraphicsItem::mousePressEvent(event);" and this works too, because the window receives the event. The problem is that, when I call setCursor(Qt::ArrowCursor) in the window class and view->viewport()->setCursor(Qt::ArrowCursor), the cursor doesn't change! When the cursor is over the view it has still a ForbiddenCursor shape, while when it is over the rest of the window it has correctly an ArrowCursor shape. So the problem is that the cursor won't go back to normal when it's over the view, even if I called view->viewport()->setCursor(Qt::ArrowCursor).
I've already tried to use unsetCursor(), to call the setCursor(Qt::ArrowCursor) both on the view and on the viewport but it doesn't work.
Strangely though the cursor changes properly back "calling the same methods" only if the user misclicks and instead of clicking on a QGraphicsItem he clicks on the view. In this case the cursor actually turns back to ArrowCursor shape even while on the view. That's pretty strange..
Could you help me please? If it's not clear enough I'll post the code.
Thanks for your help
P.S. I used QtCreator for the main window, so I actually refer to the view as ui->view. Maybe this has something to do with the problem. Thus I wanted to ask: is there a way to subclass the QGraphicsView and use my subclass with QtCreator?
Bookmarks