Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I want to synchronize the slider bar with my mouse wheel?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.7k Views
  • 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 Offline
    A Offline
    amarism
    wrote on last edited by amarism
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • A Offline
      A Offline
      ArsenArsen
      wrote on last edited by
      #2

      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
      3
      • A 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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @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
        2
        • JonBJ 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 Offline
          A Offline
          amarism
          wrote on last edited by amarism
          #4

          @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
          0
          • A ArsenArsen

            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 Offline
            A Offline
            amarism
            wrote on last edited by
            #5

            @ArsenArsen How to make slider as a cyclic?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved