Results 1 to 5 of 5

Thread: Make QDial ignore user input

  1. #1
    Join Date
    Feb 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Make QDial ignore user input

    I'd appreciate suggestions on an elegant, simple way to make QDials ignore user input but accept programmatic input.

    I could make a new class derived from QDial and override several event handlers, but I am curious if I missed some obvious 1-liner or similar.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Make QDial ignore user input

    setEnabled(false) ?

  3. #3
    Join Date
    Feb 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Make QDial ignore user input

    Thank you for the reply. Unfortunately, disabling the control makes it ignore all programmatic input until it is re-enabled. I'd still like to be able to set its position by calling its set functions.

  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: Make QDial ignore user input

    I haven't tried, but following should work:
    • Subclass QDial
    • add a custom slot where you set a privat bool (acceptUserInput)
    • reimp mouse***event, there redirect the event to the base class only if acceptUserInput is true


    Should work and in done in < 5 minutes!

  5. #5
    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: Make QDial ignore user input

    I have had 5 minutes time...
    Qt Code:
    1. class MyDial : public QDial
    2. {
    3. public:
    4. explicit MyDial(QWidget *parent = 0) : QDial(parent), m_enable(true) {}
    5. void setUserInputEnabled(bool enable)
    6. {
    7. m_enable = enable;
    8. setFocusPolicy(m_enable ? Qt::WheelFocus : Qt::NoFocus);
    9. }
    10.  
    11. protected:
    12. void mouseMoveEvent(QMouseEvent *e)
    13. {
    14. if(m_enable) QDial::mouseMoveEvent(e);
    15. }
    16. void mousePressEvent(QMouseEvent *e)
    17. {
    18. if(m_enable) QDial::mousePressEvent(e);
    19. }
    20. void mouseReleaseEvent(QMouseEvent *e)
    21. {
    22. if(m_enable) QDial::mouseReleaseEvent(e);
    23. }
    24. void keyPressEvent(QKeyEvent *e)
    25. {
    26. if(m_enable) QDial::keyPressEvent(e);
    27. }
    28. void keyReleaseEvent(QKeyEvent *e)
    29. {
    30. if(m_enable) QDial::keyReleaseEvent(e);
    31. }
    32. void wheelEvent(QWheelEvent *e)
    33. {
    34. if(m_enable) QDial::wheelEvent(e);
    35. }
    36.  
    37. private:
    38. bool m_enable;
    39. };
    To copy to clipboard, switch view to plain text mode 

    Maybe there are other events you want to disable.


    Lykurg

Similar Threads

  1. problem with reading input from user
    By ketan007 in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2009, 10:51
  2. Replies: 4
    Last Post: 24th July 2009, 08:48
  3. how to make input mask and validator work together?
    By homerli in forum Qt Programming
    Replies: 11
    Last Post: 5th June 2009, 09:53
  4. QSplitter only resize from user input?
    By winston2020 in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2009, 15:50
  5. Discard user input events in QEventLoop.
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:49

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.