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. Disable slider of scrollbar in scrollarea
QtWS25 Last Chance

Disable slider of scrollbar in scrollarea

Scheduled Pinned Locked Moved Unsolved General and Desktop
qscrollbarqscrollarea
6 Posts 3 Posters 4.0k 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
    AlexanderB
    wrote on 12 Feb 2019, 06:40 last edited by
    #1

    Hi all,

    Is it possible to disable the slider of a scrollbar in a scroll area?

    I've styled the scrollbar using css to show the arrows next to the slider. I did this by setting a width on the scrollbar, and using margins to make the slider more narrow. While this looks good, now the margin itself also responds to drag/click events. This is not what I want.

    Is there any way to disable the slider, or make the slider respond to a smaller area?

    Thanks in advance!

    R 1 Reply Last reply 12 Feb 2019, 07:08
    0
    • A AlexanderB
      12 Feb 2019, 06:40

      Hi all,

      Is it possible to disable the slider of a scrollbar in a scroll area?

      I've styled the scrollbar using css to show the arrows next to the slider. I did this by setting a width on the scrollbar, and using margins to make the slider more narrow. While this looks good, now the margin itself also responds to drag/click events. This is not what I want.

      Is there any way to disable the slider, or make the slider respond to a smaller area?

      Thanks in advance!

      R Offline
      R Offline
      Ratzz
      wrote on 12 Feb 2019, 07:08 last edited by
      #2

      @AlexanderB
      Are you looking for Qt::ScrollBarAlwaysOff link .

      --Alles ist gut.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlexanderB
        wrote on 12 Feb 2019, 07:16 last edited by
        #3

        No, the scrollbar is needed, I only want the arrows to respond to events, not the slider.

        M 1 Reply Last reply 12 Feb 2019, 07:46
        0
        • A AlexanderB
          12 Feb 2019, 07:16

          No, the scrollbar is needed, I only want the arrows to respond to events, not the slider.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 12 Feb 2019, 07:46 last edited by
          #4

          @AlexanderB
          Hi
          You could apply an event filter to the scrollbars
          (via https://doc.qt.io/qt-5/qabstractscrollarea.html#horizontalScrollBar)
          and eat those "clicks" that are outside your wanted area.
          or you could subclass QScrollBar and override mouse event function
          to alter how mouse press works.

          You can disable the scrollbars with
          ui->scrollArea->horizontalScrollBar()->setEnabled(false);
          ui->scrollArea->verticalScrollBar()->setEnabled(false);

          but that prevents any clicking.

          1 Reply Last reply
          2
          • A Offline
            A Offline
            AlexanderB
            wrote on 12 Feb 2019, 08:17 last edited by
            #5

            @mrjj

            That sounds useful! Now I'm wondering how to detect the correct area. The public API doesn't really help me, but perhaps I'm missing something obvious.

            The "actionTriggered" event seems to happen after updated the position, but before updating the UI. At his point I've already lost the current position (unless I use the "valueChanged" signal to keep track. But I hope there is an easier way to do this..

            Thanks again!

            M 1 Reply Last reply 12 Feb 2019, 18:58
            0
            • A AlexanderB
              12 Feb 2019, 08:17

              @mrjj

              That sounds useful! Now I'm wondering how to detect the correct area. The public API doesn't really help me, but perhaps I'm missing something obvious.

              The "actionTriggered" event seems to happen after updated the position, but before updating the UI. At his point I've already lost the current position (unless I use the "valueChanged" signal to keep track. But I hope there is an easier way to do this..

              Thanks again!

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 12 Feb 2019, 18:58 last edited by
              #6

              @AlexanderB

              Hi
              If you look here
              https://code.woboq.org/qt5/qtbase/src/widgets/styles/qwindowsstyle.cpp.html

              in 1894
              void QWindowsStyle::drawComplexControl

              you can see the use of
              QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
              QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);

              I assume you can get the various parts this way, even you changed it using stylesheet.

              1 Reply Last reply
              1

              6/6

              12 Feb 2019, 18:58

              • Login

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