Results 1 to 4 of 4

Thread: QSlider how to check if slider handle is selected

  1. #1
    Join Date
    May 2014
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QSlider how to check if slider handle is selected

    Hi,

    I am trying to get the slider handle to move only when it is selected and drag. I have subclass the QSlider class , re-implementing the mousePressEvent function.

    In my mousePressEvent function.

    Qt Code:
    1. Q_D(QSlider);
    2. if (d->pressedControl != QStyle::SC_SliderHandle)
    To copy to clipboard, switch view to plain text mode 

    I am unable to access d_func() as it is private , is there any work around so i am able to check if the selected object is the slider handle?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSlider how to check if slider handle is selected

    Why are you going so low level?
    Why not just use sliderPressed() signal?
    Or even better, sliderMoved()?
    http://qt-project.org/doc/qt-4.8/qab...ml#sliderMoved
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    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: QSlider how to check if slider handle is selected

    I don't think you can do that in a subclass.

    What you could try it so overwrite sliderChange() and check for value changes.
    If the slider is pressed at the time you allow it to pass, if not, you don't. The latter might require to reset the value

    Other options are to modify the slider implementation in your copy of Qt or copy the slider implementation in to a new class and have it in a separate "addon" library

    Cheers,
    _

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSlider how to check if slider handle is selected

    I am trying to get the slider handle to move only when it is selected and drag.
    but isn't this the normal QSlider behavior?
    From the docs for QAbstractSlider::sliderMoved ( int value ):
    This signal is emitted when sliderDown is true and the slider moves. This usually happens when the user is dragging the slider. The value is the new slider position.

    This signal is emitted even when tracking is turned off.
    Otherwise, what exactly do you mean by "selected and drag"?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QSlider: Increase handle size -> How ?
    By ArneBurghardt in forum Qt Programming
    Replies: 6
    Last Post: 11th August 2016, 20:58
  2. handle of Qslider in round shape using stylesheet
    By vivek.panchal in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2012, 07:13
  3. QSlider handle drawing artifacts
    By TheClassic in forum Newbie
    Replies: 3
    Last Post: 27th June 2011, 11:48
  4. How to put custom handle image in QSlider using code?
    By montylee in forum Qt Programming
    Replies: 6
    Last Post: 29th January 2009, 19:38
  5. QSlider custom handle image not displayed
    By planglois in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2008, 13: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.