Unsolved 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
ArsenArsen last edited by
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.
JonB last edited by JonB
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
QScrollBarworks 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
QScrollAreato handle the "scrolling" for you.
connect(ui->Slider, SIGNAL(valueChanged(int)), this, SLOT(SetSlice(int)));
void QMainWindow::SetSlice(int SliderPos)
qDebug() << SliderPos;
if (!mainObject) return; if(ui->Slider->hasFocus()) 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); QSliderWidget->setMinimum(m_SliceMin); QSliderWidget->setMaximum(m_SliceMax); return qMakePair(m_SliceMax , m_SliceMin);
@ArsenArsen How to make slider as a cyclic?