Results 1 to 8 of 8

Thread: Changing cursor shape

  1. #1
    Join Date
    Nov 2011
    Location
    Poland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question Changing cursor shape

    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
    ----------------------------------------------------------
    Qt Code:
    1. #include <QApplication>
    2. #include "Problem.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. Problem win;
    8. win.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    ----------------------------------------------------------
    problem.h
    ----------------------------------------------------------
    Qt Code:
    1. #include <QWidget>
    2.  
    3. class Problem : public QWidget
    4. {
    5. public:
    6. Problem();
    7. protected:
    8. void mousePressEvent(QMouseEvent *event);
    9. void mouseReleaseEvent(QMouseEvent *event);
    10. };
    To copy to clipboard, switch view to plain text mode 

    ----------------------------------------------------------
    problem.cpp
    ----------------------------------------------------------
    Qt Code:
    1. #include <QtGui>
    2. #include "Problem.h"
    3.  
    4. Problem::Problem()
    5. {
    6. setWindowTitle(" ? ");
    7. setGeometry(50,50,500,300);
    8. setCursor(Qt::OpenHandCursor);
    9.  
    10. QLabel *Label = new QLabel("Label area", this);
    11. Label->setFrameStyle(1);
    12. Label->setGeometry(100,100,200,20);
    13. }
    14. void Problem::mousePressEvent(QMouseEvent *event)
    15. {
    16. setCursor(Qt::ClosedHandCursor);
    17. setWindowTitle(" ClosedHandCursor "));
    18. }
    19. void Problem::mouseReleaseEvent(QMouseEvent *event)
    20. {
    21. setCursor(Qt::OpenHandCursor);
    22. setWindowTitle(" OpenHandCursor "));
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 18th November 2011 at 10:19. Reason: missing [code] tags

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Changing cursor shape

    try unset cursor for this label.

  3. #3
    Join Date
    Nov 2011
    Location
    Poland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing cursor shape

    I'm sorry, but it not makes any changes.
    And even, then what to do if I would like another cursor for window
    and another cursor for label (see below)?
    Thank you for your help!

    Qt Code:
    1. Problem::Problem()
    2. {
    3. setWindowTitle(" ? ");
    4. setGeometry(50,50,500,300);
    5. setCursor(Qt::OpenHandCursor); // <--- cursor for window
    6.  
    7. QLabel *Label = new QLabel("Label area", this);
    8. Label->setFrameStyle(1);
    9. Label->setGeometry(100,100,200,20);
    10. Label->setCursor(Qt::IBeamCursor); // <---- cursor for label
    11. }
    12.  
    13. void Problem::mousePressEvent(QMouseEvent *event)
    14. {
    15. setCursor(Qt::ClosedHandCursor);
    16. setWindowTitle(" ClosedHandCursor "));
    17. }
    18.  
    19. void Problem::mouseReleaseEvent(QMouseEvent *event)
    20. {
    21. setCursor(Qt::OpenHandCursor);
    22. setWindowTitle(" OpenHandCursor "));
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 18th November 2011 at 10:19. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Changing cursor shape

    Hi Odyseusz,

    I don't get your problem to be honest. The first program works as expected: Whether you click on the window or on the label, the shape changes (because the label adopt the behavior of its parent (the window)). On the second, over the label it changes to IBeamCursor and even if you press it still have that shape, because you change the cursor on the window not on the label. And since the press event was on the label, it stays "active" even if you move the cursor over the window.

    If that does not answer your question please elaborate what exactly you expect (based on which actions).

    Best

  5. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Changing cursor shape

    I meant: Lable->unsetCursor();

  6. #6
    Join Date
    Nov 2011
    Location
    Poland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing cursor shape

    ------------------------------------------------------------
    To MarekR22
    ------------------------------------------------------------
    As I wrote in post #3 this instruction hasn't any effect!

    Thank you for your help!

    ---------------------------------------------------------------------------
    To Lykurg
    ---------------------------------------------------------------------------
    First - I'm clicking on the window and the cursor changes as expected
    (open hand - closed hand);
    Next - I'm moving the cursor to the label and I'm clicking on this label:
    in first example cursor changes as expected (open hand - closed hand),
    in second example cursor changes to IBeam and of course not changes;
    Then - I'm moving the cursor back to the window - in both cases the cursor
    changes to open hand (as expected) - BUT, if now I'm clicking
    on the window the cursor stays still open hand (no regard,
    if I clicked on the label in step Next or only moved the cursor
    over the label) - THIS IS MY PROBLEM!

    Thank you for your help!

    Sorry for my english!

  7. #7
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Changing cursor shape

    Yep, it's happening and it's odd.
    QCursor::shape() returns correct value in mousePress/Release but the visible shape of the cursor doesn't change.

    No idea why it's happening.

  8. #8
    Join Date
    Nov 2011
    Location
    Poland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing cursor shape

    Spitfire, thank you for your attempt!

Similar Threads

  1. Replies: 0
    Last Post: 18th January 2011, 17:59
  2. QDockWidget splitter, cursor shape
    By alecs1 in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2007, 19:44
  3. Shape changing under other tab using slider/spinbox
    By kramed in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 20:59
  4. Cursor not changing
    By bpetty in forum Newbie
    Replies: 4
    Last Post: 17th July 2007, 16:13
  5. Shape-changing dialog with qt4.1
    By moe in forum Qt Tools
    Replies: 3
    Last Post: 2nd February 2006, 11:12

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.