Results 1 to 4 of 4

Thread: Help with the setCursor() method

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Help with the setCursor() method

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with the setCursor() method

    This behavior is a bit weird.

    Have you verified that the setCursor(Qt::ArrowCursor) call is actually executed when you click on an item?

    Cheers,
    _

  3. #3
    Join Date
    Nov 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Help with the setCursor() method

    Yes, since it changes the cursor for everything else. It's just when it comes to the graphic view that it doesn't work.

    I've just noticed that if I never click on the graphicsView nor on the graphicsItems, it works by setting only window->setCursor(): the cursor changes also on the view. But if I interact with the view before calling the window->setCursor(), it doesn't change the cursor anymore on the view, but only on the rest of the window. Might it be a focus problem?

    I would subclass the view to see if it is somehow modifying the cursor but I can't since I added the view through QtDesigner...

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with the setCursor() method

    You can create your own subclass and then use "promote widget" in Designer to make it an instance of your widget.

    Cheers,
    _

Similar Threads

  1. setCursor & a disabled Widget
    By FoX_*D i E* in forum Qt Programming
    Replies: 3
    Last Post: 16th September 2008, 10:27
  2. setcursor problem
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 17th May 2008, 16:58
  3. setCursor
    By ^NyAw^ in forum Qt Programming
    Replies: 9
    Last Post: 16th May 2008, 12:43
  4. setCursor
    By mickey in forum Qt Programming
    Replies: 4
    Last Post: 23rd April 2006, 20:39
  5. setCursor(Qt::WaitCursor);
    By fellobo in forum Qt Programming
    Replies: 1
    Last Post: 1st March 2006, 03:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.