Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSlider Handle Size



  • Is there any way to obtain the physical geometry of the handle belonging to a QSlider?

    I'm wanting to get the pixel location of the centre point of the handle so I can then draw text above it.



  • QStyleOptionSlider opt;
    initStyleOption(&opt);
    opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
    QRect handleRect =style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
    


  • @VRonin Thanks for your response.

    This seems pretty good. One question though, which header file contains the initStyleOption declaration?



  • Please ignore my last comment. I wasn't subclassing the QSlider when I made that comment.


Log in to reply