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. [SOLVED] - QSlider - Adding a "target" zone?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] - QSlider - Adding a "target" zone?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 1.3k 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.
  • M Offline
    M Offline
    maximus
    wrote on 6 Aug 2014, 18:44 last edited by
    #1

    I would like to achieve something similar to this :
    https://www.dropbox.com/s/5rxijbet43jg40n/targetSliderWidget.png

    Basically, just a normal QSlider, where the Slider represent the current value of a real time data (i.e : Heart rate)
    the colored "zone" area would be the target to achieve.

    I'm not sure if QSlider can achieve this, Is there a way to change a specific segment on the QSlider to a different color? I have not found any stylesheet example that does this, it use pixel but I would need precise values.

    My value would are in percentage
    For example.
    Zone to achieve : [5-10%] (colored zone)
    Current Value : 15% (slider)

    Any idea/help appreciated, I'm also considering QProgressBar, not sure which widget is the best to use for this use-case.
    Thank you!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on 6 Aug 2014, 18:57 last edited by
      #2

      With the QtStylesheet Example, I achieved this :
      https://www.dropbox.com/s/xlk0txnmm9ghfcr/QSliderZone1.png

      It's almost what I want, but the "zone" area is draw with stylesheet, I think it could work in my program, but the zone will change at runtime so updating the zone could be a pain, will try and post result

      @ QSlider::groove:horizontal {
      border: 1px solid #999999;
      height: 25px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
      background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0.0 white, stop:0.20 white, stop:0.21 pink, stop:0.39 pink, stop:0.40 white, stop:1.0 white);
      margin: 2px 0;
      }

      QSlider::handle:horizontal {
      background: red;
      border: 1px solid #5c5c5c;
      width: 18px;
      margin: -2px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
      border-radius: 3px;
      }@


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      1
      • M Offline
        M Offline
        maximus
        wrote on 6 Aug 2014, 19:34 last edited by
        #3

        Stylesheet FTW!

        @
        void BalanceWidget::setZone(int low, int high) {

        zoneLow = low;
        zoneHigh  = high;
        
        double zoneLow_d = low / 100.0;
        double zoneHigh_d = high / 100.0;
        double beforeZoneLow;
        double afterZoneHigh;
        
        if (zoneLow_d == 0.0) {
            beforeZoneLow = zoneLow_d;
        }
        else {
            beforeZoneLow = zoneLow_d - 0.01;
        }
        
        if (zoneHigh_d == 1.0) {
            afterZoneHigh = zoneHigh_d;
        }
        else {
            afterZoneHigh = zoneHigh_d + 0.01;
        }
        
        
        qDebug() << "beforeZoneLow Is:" << QString::number(beforeZoneLow);
        
        ui->horizontalSlider->setStyleSheet("QSlider::groove:horizontal { background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0.0 white, stop:"+ QString::number(beforeZoneLow) + " white, stop:"+ QString::number(zoneLow_d) + " blue, stop:"+ QString::number(zoneHigh_d) + " blue, stop:"+ QString::number(afterZoneHigh) + " white, stop:1.0 white); }");
        

        }@


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        0

        1/3

        6 Aug 2014, 18:44

        • Login

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