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. Use qss to custom QSlider.
Forum Updated to NodeBB v4.3 + New Features

Use qss to custom QSlider.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 510 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.
  • S Offline
    S Offline
    sven1991
    wrote on last edited by
    #1

    I want to use qss to custom QSlider, and I want to use border-radius property to make QSlider to rounded corners, my code as below.

    QSlider::groove:horizontal {
    border: 1px solid #FFFFFF;
    border-radius: 20px;
    }
    
    QSlider::sub-page:horizontal {
    background: rgb(90,49,255);
    border-radius: 20px;
    }
    
    QSlider::add-page:horizontal {
    background: transparent;
    }
     
    QSlider::handle:horizontal {
        width: 0px;                 
        height: 0px;                
        background-color: transparent;    
    }
    

    Animation.gif
    It when the progress bar gets very small, it turns into a rectangle. How can I fix it?
    I simply want QSlider to support rounded corners, what are the alternatives?

    B 1 Reply Last reply
    0
    • S sven1991

      I want to use qss to custom QSlider, and I want to use border-radius property to make QSlider to rounded corners, my code as below.

      QSlider::groove:horizontal {
      border: 1px solid #FFFFFF;
      border-radius: 20px;
      }
      
      QSlider::sub-page:horizontal {
      background: rgb(90,49,255);
      border-radius: 20px;
      }
      
      QSlider::add-page:horizontal {
      background: transparent;
      }
       
      QSlider::handle:horizontal {
          width: 0px;                 
          height: 0px;                
          background-color: transparent;    
      }
      

      Animation.gif
      It when the progress bar gets very small, it turns into a rectangle. How can I fix it?
      I simply want QSlider to support rounded corners, what are the alternatives?

      B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      @sven1991 You can't have 20px radius rounded corners when the width/height is less than 20px.

      S 1 Reply Last reply
      1
      • B Bonnie

        @sven1991 You can't have 20px radius rounded corners when the width/height is less than 20px.

        S Offline
        S Offline
        sven1991
        wrote on last edited by
        #3

        @Bonnie Thanks for you reply. What should I do? I just want to use QSlider with rounded corner.

        JonBJ B 2 Replies Last reply
        0
        • S sven1991

          @Bonnie Thanks for you reply. What should I do? I just want to use QSlider with rounded corner.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @sven1991
          Well at some point the width becomes too small to have a 20px rounded corner. I guess if you really want something which works then you'll have to reduce your 20px, by dynamically adding a stylesheet to the slider with a new QSlider::sub-page:horizontal rule with a smaller radius. Or possibly doing it via a dynamic property.

          1 Reply Last reply
          1
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #5

            You could try using the "white curtains" trick:

            extend the progressbar 20px to the left
            create a white inert QWidget with the same height and left coord as the progressbar but only 20px width, set to have the same parent widget as the progressbar (so they are siblings).
            Then call a stackUnder(QWidget) for the progressbar so that the QWidget sits on top of the first 20px of the progressbar.

            You have to remember to skip over the first couple of percent of progress before the progressbar is visible, but the rounded corners will look nice :-)

            1 Reply Last reply
            2
            • S sven1991

              @Bonnie Thanks for you reply. What should I do? I just want to use QSlider with rounded corner.

              B Offline
              B Offline
              Bonnie
              wrote on last edited by Bonnie
              #6

              @sven1991 Besides the good suggestions from @JonB and @hskoglund , I also feel that your animation looks more like a QProgressBar than a QSlider. Why would you need a slider with transparent handle and sub-page?
              But even with QProgressBar, the radius problem is still as the same as QSlider.

              1 Reply Last reply
              1
              • B Bonnie referenced this topic on

              • Login

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