Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Does anyone know how to make a custom scrollbar that looks as follows:
Qt 6.12 LTS is out! See what's new in the release blog

Does anyone know how to make a custom scrollbar that looks as follows:

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 3 Posters 1.2k Views 2 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.
  • S Offline
    S Offline
    sherief
    wrote on last edited by
    #1

    I've been messing around with creating my own scrollbar class to make it look like a specific one (I'll attach it). The problem I keep having is that the scroll arrows are only hidden and not removed, so the scrollbar doesn't fully scroll down. I also don't know how to make the scroll area a different color than the rest of the table that it's on. I'll attach the example and the code I have so far.

    Code:

    class CustomScrollBar(QtWidgets.QScrollBar):
    def init(self, *args, **kwargs):
    QtWidgets.QScrollBar.init(self, *args, **kwargs)
    self.baseSheet = '''
    QScrollBar::right-arrow:vertical, QScrollBar::left-arrow:vertical{{
    border: none;
    background: none;
    color: none;
    }}

            QScrollBar::add-line:vertical {{
              border: none;
              background: none;
            }}
    
            QScrollBar::sub-line:vertical {{
              border: none;
              background: none;
            }}
           
          
            '''
       
        self.setStyleSheet(self.baseSheet.format())
    

    Example: https://ibb.co/cT4TbtB

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @sherief if you go look at the documentation here (https://doc.qt.io/qt-5/classes.html#) and pull up QScrollBar you would find that it inherits from QAbstractSlider which in turn inherits from QWidget.

      So the chances are if you want to create your own QScrollBar you will probably need to use its parent QAbstractSlider or its grand-parent QWidget to implement the things you are attempting to do.

      Note not only does QScrollBar inherit from QAbstractSlider but also QDial and QSlider do as well so if you wanting ideas on how to manipulate the QAbstractSlider perhaps these other two child classes might help you.

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        If you mean for it to have no arrows.
        then something like
        alt text

        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
        • Unsolved