Important: Please read the Qt Code of Conduct -

I want to synchronize the slider bar with my mouse wheel?

  • I have a grid view and showing the multiple images using the slider bar top to bottom. I have a query when I slider the bar, an image will change inside the grid, after a middle of the slider, I try to scroll the mouse wheel. The image will be changing from the first image. I need to synchronize the mouse wheel and slider bar. Once the mouse wheel rotates respective to the slider bar also move. Also, I need a cyclic slider bar.

    I am attaching the image view :


    Thanks for your help

  • Qt provides a wheel event that you can use. Simply calculate the amount to change the slider according to the delta value. It would also possibly be better to look at alternative implementations which could provide a scroll area for you.

  • @amarism
    I presume that "Slider" you show is a QSlider? From what I have seen I would expect that to correctly scroll for mousewheel as well as mouse-slider-drag. You suggest they are not "integrated", in that doing a mousewheel re-starts from the top ignoring where the user has already mouse-dragged the slider too, is that right? You might need to show the code being used, because my thought is that it ought be working the way you want already.

    You might alternatively see if a QScrollBar works better for you (it should certainly handle mouse drag + mousewheel together) if you are not wedded to a QSlider. As @ArsenArsen said, you might want instead to change code over to using something like a QScrollArea to handle the "scrolling" for you.

  • @JonB


    connect(ui->Slider, SIGNAL(valueChanged(int)), this, SLOT(SetSlice(int)));

    void QMainWindow::SetSlice(int SliderPos)
    qDebug() << SliderPos;

    if (!mainObject)
    	mainObject->ImageSlicing(ui->Slider->sliderPosition(), 0);



    void Viewer::ImageSlicing(int QtSliderPos, int view)
    if (view > 2)
    int CurrSlice = ResliceViewer[view]->GetSlice();



    QPair<int, int> Viewer::GetSetSliceRange(QSlider *QSliderWidget, int view)
    int SliceMax = ResliceViewer[view]->GetSliceMax();
    int SliceMin = ResliceViewer[view]->GetSliceMin();

    if (!QSliderWidget)
    	return qMakePair(m_SliceMax, m_SliceMin);
    return qMakePair(m_SliceMax , m_SliceMin);


  • @ArsenArsen How to make slider as a cyclic?

Log in to reply