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: show bar from center +/-
Qt 6.11 is out! See what's new in the release blog

QSlider: show bar from center +/-

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 557 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    daniel.barna
    wrote on last edited by
    #1

    Hello,
    Sorry if this has been asked/answered, I could not find it. I would like to use a slider which goes from -100 to 100. By default, the blue bar is drawn from the leftmost corner, i.e. from -100 to the given value. How can it be changed so that the blue bar is drawn between the central value (0) and the actual value?
    Thank you
    Daniel

    Pl45m4P 1 Reply Last reply
    0
    • D daniel.barna

      Hello,
      Sorry if this has been asked/answered, I could not find it. I would like to use a slider which goes from -100 to 100. By default, the blue bar is drawn from the leftmost corner, i.e. from -100 to the given value. How can it be changed so that the blue bar is drawn between the central value (0) and the actual value?
      Thank you
      Daniel

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @daniel-barna said in QSlider: show bar from center +/-:

      How can it be changed so that the blue bar is drawn between the central value (0) and the actual value?

      slider->setRange(-100, 100);
      slider->setValue(0);
      

      This meets your requirements, but it is probably not what you are looking for...
      For custom style and behavior, you have to write your own slider widget

      Edit:

      You have this:

      |-----|-----|-----|-----|-----|-----|
      ^

      and want this?

      |-----|-----|-----|-----|-----|-----|
                        ^

      the blue bar is drawn from the leftmost corner, i.e. from -100 to the given value

      You must be on MacOS then, right?!
      Could be an OS specific thing. I dont know how sliders are natively drawn on macOS but probably the bar starts at the origin. So for your goal you would need to move the origin to the center of your scale and go from there (left for negative values, right for positive).


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

      ~E. W. Dijkstra

      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