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. QSlider linked with other QSlider - hints needed

QSlider linked with other QSlider - hints needed

Scheduled Pinned Locked Moved Solved General and Desktop
qslider
4 Posts 2 Posters 343 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.
  • M Offline
    M Offline
    MasterBLB
    wrote on 19 May 2024, 20:03 last edited by MasterBLB
    #1

    Hello colleagues

    I'm working on the such topic:

    1. I have 2 objects of MirroredSlider : public QSlider
    2. Both have the same singleStep and pageStep set.
    3. The goal I'd like to achieve is - when I hold down CTRL key, and change value of the 1st slider using GUI input then the other slider accordingly goes up/down single step. As a bonus - would be nice to handle usual keyboard input for QSlider too.
    4. Starting values of both sliders don't have to match.

    Tried reimplementing events, like

    void MirroredSlider::wheelEvent(QWheelEvent *event)
    {
        if (mirroredSlider && event->modifiers() == Qt::ControlModifier)
        {
            QWheelEvent *e = new QWheelEvent(QPointF(), 0, 0, 0);
            *e = *event;
            e->setModifiers(Qt::NoModifier);
            qApp->postEvent(mirroredSlider, e);
        }
        QSlider::wheelEvent(event);
    }
    //and for grabbing and moving slider handle
    void MirroredSlider::mouseMoveEvent(QMouseEvent *event)
    {
        oldValue = value();
        QSlider::mouseMoveEvent(event);
        if (mirroredSlider && event->modifiers() == Qt::ControlModifier)
        {
            if (oldValue > value())
            {
                mirroredSlider->triggerAction(QAbstractSlider::SliderSingleStepSub);
            }
            else if (oldValue < value())
            {
                mirroredSlider->triggerAction(QAbstractSlider::SliderSingleStepAdd);
            }
        }
    }
    

    The above works fine for mouse wheel and moving handle by mouse, but fails when I point anywhere on the slider, and press and hold left mouse button; btw a curiosity, log placed inside event(QEvent*) for that case shows 1st mousePress, then timer events as longs as the button is held down, then mouseRelease.

    I tried to use signal valueChanged() and actionTriggered(), but also turned out to be not good enough solution.

    Is there something else I should put my attention to?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MasterBLB
      wrote on 19 May 2024, 22:12 last edited by
      #2

      And again, soon after I post here I get stroke of genius, and find solution on my own. Happens almost every time.

      P 1 Reply Last reply 20 May 2024, 00:53
      0
      • M MasterBLB has marked this topic as solved on 19 May 2024, 22:12
      • M MasterBLB
        19 May 2024, 22:12

        And again, soon after I post here I get stroke of genius, and find solution on my own. Happens almost every time.

        P Offline
        P Offline
        Pl45m4
        wrote on 20 May 2024, 00:53 last edited by
        #3

        @MasterBLB said in QSlider linked with other QSlider - hints needed:

        And again, soon after I post here I get stroke of genius, and find solution on my own. Happens almost every time.

        Rubber Duck Debugging at its best :))


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        M 1 Reply Last reply 20 May 2024, 07:58
        1
        • P Pl45m4
          20 May 2024, 00:53

          @MasterBLB said in QSlider linked with other QSlider - hints needed:

          And again, soon after I post here I get stroke of genius, and find solution on my own. Happens almost every time.

          Rubber Duck Debugging at its best :))

          M Offline
          M Offline
          MasterBLB
          wrote on 20 May 2024, 07:58 last edited by MasterBLB
          #4

          @Pl45m4 said in QSlider linked with other QSlider - hints needed:

          @MasterBLB said in QSlider linked with other QSlider - hints needed:

          And again, soon after I post here I get stroke of genius, and find solution on my own. Happens almost every time.

          Rubber Duck Debugging at its best :))

          Yepp, though before posting I spent several hours testing different approaches - most interesting finding was that for press and hold lmb on non-handle element of the slider invokes timer events. The most important discovery was:

          1. value() returns something
          2. an event happens
          3. if the event was some kind which affect the value now, just after QSlider::event(), the value() should be different

          after realizing that the rest was easy.

          1 Reply Last reply
          0

          1/4

          19 May 2024, 20:03

          • Login

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