Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    3
    5
    1126
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      amarism last edited by amarism

      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 :

      0_1532613919831_slider.png

      Thanks for your help
      Amar

      JonB 1 Reply Last reply Reply Quote 0
      • A
        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.

        A 1 Reply Last reply Reply Quote 3
        • JonB
          JonB @amarism last edited by JonB

          @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.

          A 1 Reply Last reply Reply Quote 2
          • A
            amarism @JonB last edited by amarism

            @JonB

            MainWindow.cpp

            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);
            

            }

            viewer.cpp

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

            	ResliceViewer[view]->SetSlice(QtSliderPos);
            	ResliceViewer[view]->Modified();
            

            }

            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);
            

            }

            1 Reply Last reply Reply Quote 0
            • A
              amarism @ArsenArsen last edited by

              @ArsenArsen How to make slider as a cyclic?

              1 Reply Last reply Reply Quote 0
              • First post
                Last post