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. Styling scrollbar with CSS
Forum Updated to NodeBB v4.3 + New Features

Styling scrollbar with CSS

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • T Offline
    T Offline
    Thyringer
    wrote on 20 Mar 2022, 16:40 last edited by Thyringer
    #1

    I'm trying to give all the app's scrollbars a specific design using CSS. I have achieved everything as desired so far; but I still haven't figured out how to make 'handle' the same width as the top and bottom scroll buttons. How do you do that?

    CSS code (format string literal in Python / PySide2):

    scrollbar_design = f"""
    	QScrollBar {{
    		background: #D3D3D3;
    		border: none;
    		margin: 0;
    		padding: 0;
    		width: 30px;
    	}}
    	
    	QScrollBar:groove {{
    		border-radius: 5px;
    		background: gray;
    		margin: 25px 0;
    		width: 30px;
    	}}
    	
    	QScrollBar:handle {{
    		border: none;
    		background: #D3D3D3;
    		margin: 25px 0;
    		min-height: 30px;
    		min-width: 30px;
    	}}
    		
    	QScrollBar:sub-line {{
    		background: #F29100;
    		border: none;
    		height: 30px;
    		padding: 0;
    		width: 30px;
    	}}
    	
    	/*
    	QScrollBar:sub-line:vertical {{
    		border-image: url({window.catalog.icon.control["up.png"]});
    	}}
    	*/
    	
    	QScrollBar:add-line {{
    		background:  #F29100;
    		border: none;
    		height: 30px;	
    		padding: 0;
    		width: 30px;
    	}}
    	
    	/*
    	QScrollBar:add-line:vertical {{
    		border-image: url({window.catalog.icon.control["expand.png"]});
    	}}
    	*/
    """
    

    I commented out the code for the arrow images and only included it for the sake of completeness.

    Screenshot_20220320_173536.png
    Screenshot_20220320_173656.png

    The first picture shows the desired design, the bottom shows my actual implementation.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Thyringer
      wrote on 22 Mar 2022, 13:00 last edited by
      #3

      Thanks for the answer!
      the groove doesn't belong there anyway, and was deleted. I just "played" with it to see what kind of effects it had.

      I found the problem myself: Another global widget's properties were interfering with my scrollbar's.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Ewan Green
        wrote on 20 Mar 2022, 21:47 last edited by
        #2

        QScrollBar::groove and QScrollBar::handle both have 25px horizontal padding. You don't want that if you're trying to make your scroll bar flush with the scroll buttons.

        Ewan Green

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Thyringer
          wrote on 22 Mar 2022, 13:00 last edited by
          #3

          Thanks for the answer!
          the groove doesn't belong there anyway, and was deleted. I just "played" with it to see what kind of effects it had.

          I found the problem myself: Another global widget's properties were interfering with my scrollbar's.

          1 Reply Last reply
          0

          1/3

          20 Mar 2022, 16:40

          • 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