Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ScrollBar policy not working as expected
QtWS25 Last Chance

ScrollBar policy not working as expected

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
scrollbar
5 Posts 2 Posters 462 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    According to the docs:

    ScrollBar.AsNeeded The scroll bar is only shown when the content is too large to fit.

    So then, why, in this example:

    ApplicationWindow {
        id: mainWindow
    
        visible: true
        width: 640
        height: 480
    
        ScrollView {
            id: scrollView
            height: 200
            width: 400
            contentHeight: textArea.contentHeight
    
            TextArea {
                id: textArea
                text: "top\nbottom"
                background: Rectangle {
                    width: scrollView.width
                    color: 'lightgray'
                    border.width: 1
                }
            }
    
            ScrollBar.vertical: ScrollBar {
                id: scroller
                policy: ScrollBar.AsNeeded
                anchors.left: scrollView.right
                contentItem: Rectangle {
                    implicitHeight: scrollView.height
                    implicitWidth: 12
                    color: 'lightblue'
                }
                background: Rectangle {
                    anchors.fill: parent
                    color: 'transparent'
                }
            }
        }
    }
    

    Do I get a visible ScrollBar?
    scroll.PNG

    I've tried with Fusion and Universal (running on Windows) - same result.

    Thanks...

    JoeCFDJ 2 Replies Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      According to the docs:

      ScrollBar.AsNeeded The scroll bar is only shown when the content is too large to fit.

      So then, why, in this example:

      ApplicationWindow {
          id: mainWindow
      
          visible: true
          width: 640
          height: 480
      
          ScrollView {
              id: scrollView
              height: 200
              width: 400
              contentHeight: textArea.contentHeight
      
              TextArea {
                  id: textArea
                  text: "top\nbottom"
                  background: Rectangle {
                      width: scrollView.width
                      color: 'lightgray'
                      border.width: 1
                  }
              }
      
              ScrollBar.vertical: ScrollBar {
                  id: scroller
                  policy: ScrollBar.AsNeeded
                  anchors.left: scrollView.right
                  contentItem: Rectangle {
                      implicitHeight: scrollView.height
                      implicitWidth: 12
                      color: 'lightblue'
                  }
                  background: Rectangle {
                      anchors.fill: parent
                      color: 'transparent'
                  }
              }
          }
      }
      

      Do I get a visible ScrollBar?
      scroll.PNG

      I've tried with Fusion and Universal (running on Windows) - same result.

      Thanks...

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @mzimmers
      one way to make it working

      ApplicationWindow {
          id: mainWindow
      
          visible: true
          width: 640
          height: 480
      
          ScrollView {
              id: scrollView
              height: 200
              width: 400
              contentHeight: textArea.contentHeight
      
              TextArea {
                  id: textArea
                  text: "top\nbottom\ntop\nbottom\nbottom\ntop\nbottom\nbottom\ntop\nbottom\nbottom\ntop\nbottom\nbottom\ntop\nbottom"
                  background: Rectangle {
                      width: scrollView.width
                      color: 'lightgray'
                      border.width: 1
                  }
              }
      
              ScrollBar.vertical: ScrollBar {
                  id: scroller
                  anchors.right: scrollView.right /*   anchors.left or right? */
                  visible: textArea.contentHeight > scrollView.height
      
                  contentItem: Rectangle {
                      implicitHeight: scrollView.height
                      implicitWidth: 12
                      color: 'lightblue'
                  }
          
                  background: Rectangle {
                      anchors.fill: parent
                      color: 'transparent'
                  }
              }
          }
      }
      
      
      1 Reply Last reply
      1
      • mzimmersM mzimmers

        Hi all -

        According to the docs:

        ScrollBar.AsNeeded The scroll bar is only shown when the content is too large to fit.

        So then, why, in this example:

        ApplicationWindow {
            id: mainWindow
        
            visible: true
            width: 640
            height: 480
        
            ScrollView {
                id: scrollView
                height: 200
                width: 400
                contentHeight: textArea.contentHeight
        
                TextArea {
                    id: textArea
                    text: "top\nbottom"
                    background: Rectangle {
                        width: scrollView.width
                        color: 'lightgray'
                        border.width: 1
                    }
                }
        
                ScrollBar.vertical: ScrollBar {
                    id: scroller
                    policy: ScrollBar.AsNeeded
                    anchors.left: scrollView.right
                    contentItem: Rectangle {
                        implicitHeight: scrollView.height
                        implicitWidth: 12
                        color: 'lightblue'
                    }
                    background: Rectangle {
                        anchors.fill: parent
                        color: 'transparent'
                    }
                }
            }
        }
        

        Do I get a visible ScrollBar?
        scroll.PNG

        I've tried with Fusion and Universal (running on Windows) - same result.

        Thanks...

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3
        This post is deleted!
        mzimmersM 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          This post is deleted!

          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          @JoeCFD your first suggestion works (I couldn't get the second one to work). I'm curious, though - why is this necessary?

          JoeCFDJ 1 Reply Last reply
          0
          • mzimmersM mzimmers

            @JoeCFD your first suggestion works (I couldn't get the second one to work). I'm curious, though - why is this necessary?

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            @mzimmers True that the second one does not work. Sorry! I tested it and saw it worked. I must have done something differently. I will check it out later.

            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