Results 1 to 2 of 2

Thread: QDial value wrapping restriction.

  1. #1
    Join Date
    Nov 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QDial value wrapping restriction.

    Hi All,

    I'm using QDial and I have used setWrapping(false) function to restrict the QDial movement beyond max/min position. But still the QDial wraps to minimum after dragging beyond maximum range of QDial.

    Is there any way to restrict the QDial so that it stays in maximum/minimum position?

    Any help in solving this issue is really appreciated.

    Thanks,
    Dheeraj

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QDial value wrapping restriction.

    You can connect to actionTriggered(int) signal and prevent moving the slider to new value when current value is minimum() or maximum(), and new value seems to be "wrapped". Watch for QAbstractSlider::SliderMove action:
    Qt Code:
    1. class NoWrapDial : public QDial{
    2. Q_OBJECT
    3. public:
    4. NoWrapDial(QWidget * parent = NULL) : QDial(parent)
    5. {
    6. connect(this, SIGNAL(actionTriggered(int)), this, SLOT(onAction(int)));
    7. }
    8. protected slots:
    9. void onAction(int val){
    10. static const int minDistance = 1;
    11. if (val == QAbstractSlider::SliderMove) {
    12. if (value() == maximum() && sliderPosition()<maximum()-minDistance) {
    13. this->setSliderPosition(maximum());
    14. } else if (value() == minimum() && sliderPosition()>minimum()+minDistance){
    15. this->setSliderPosition(minimum());
    16. }
    17. }
    18. }
    19. };
    To copy to clipboard, switch view to plain text mode 

    btw. this requires tracking to be enabled (the default)
    Last edited by stampede; 21st November 2013 at 16:45.

Similar Threads

  1. how to subclass QDial?
    By banlinhtienphong in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2011, 07:54
  2. Customize QDial
    By Jayes in forum Qt Programming
    Replies: 10
    Last Post: 23rd December 2010, 04:44
  3. QDial in Qt4.6 is without needle?
    By raedbenz in forum Qt Programming
    Replies: 9
    Last Post: 16th July 2010, 14:57
  4. How can I resize needle of QDial
    By validator in forum Qt Tools
    Replies: 1
    Last Post: 1st February 2008, 10:10
  5. QDial
    By mickey in forum Newbie
    Replies: 4
    Last Post: 18th June 2006, 12:01

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.