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. Flickable and ScrollBar not working as desired
Forum Updated to NodeBB v4.3 + New Features

Flickable and ScrollBar not working as desired

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 1 Posters 1.4k 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    Hi all -

    I'm having problems properly setting the height of a Flickable, and as a result (I think) the ScrollBar isn't working correctly.

    I've cut the code down as much as possible:

    import QtQuick
    import QtQuick.Controls
    import QtQuick.Layouts
    import colors.stylesheet
    
    Column {
        id: mainGrid
    
        RowLayout {
            id: sliderRow
            Layout.fillHeight: true
            Layout.fillWidth: true
    
            Repeater {
                model: 4
                Tileslider { descrip: "slider " + index }
            }
        }
    
        Flickable {
            id: flickable
    
            height: gridEquipment.height // WRONG
            width: gridEquipment.width // WRONG
    
            ScrollBar.vertical: ScrollBar {
                orientation: Qt.Vertical
                policy: ScrollBar.AlwaysOn
            }
    
            GridLayout {
                id: gridEquipment
    
                rows: 3
                columns: 4
    
                Repeater {
                    model: 8
                    Tileicon { titleText: "tile " + index }
                }
            }
        }
    }
    

    And I'm getting this:
    main.PNG

    So, the question is, how do I correctly set the height of the Flickable? The main window height is fixed, as are the tab bar and the area reserved for filters.

    EDIT:

    In case it isn't clear, that pic is my entire display window. I need the entire scrollbar visible.

    Thanks...

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #2

      BTT.

      I've created a simpler example, that shows a similar problem. With this code:

      import QtQuick
      import QtQuick.Controls
      import QtQuick.Layouts
      
      ApplicationWindow {
          visible: true
          width: 800
          height: 480
      
      //    Flickable {
          ScrollView {
          anchors.fill: parent
              ColumnLayout {
                  Rectangle { id: r1; width: 100; height: 600; color: "yellow"; Text { text: "xxx" } }
                  Rectangle { id: r2; width: 100; height:  24; color: 'gray';   Text { text: "yyy" } }
              }
              ScrollBar {
                  orientation: Qt.Vertical
                  anchors {top: parent.top; right: parent.right; bottom: parent.bottom }
              }
          }
      }
      
      

      I get this:
      scrollbar.PNG

      Moving the scrollbar doesn't change the view. I'd expect eventually to get to the bottom of the yellow rectangle and see the gray one. How is that the scrollbar isn't affecting the contents of the Scrollview/Flickable (I've tried both)?

      Thanks...

      mzimmersM 1 Reply Last reply
      0
      • mzimmersM mzimmers

        BTT.

        I've created a simpler example, that shows a similar problem. With this code:

        import QtQuick
        import QtQuick.Controls
        import QtQuick.Layouts
        
        ApplicationWindow {
            visible: true
            width: 800
            height: 480
        
        //    Flickable {
            ScrollView {
            anchors.fill: parent
                ColumnLayout {
                    Rectangle { id: r1; width: 100; height: 600; color: "yellow"; Text { text: "xxx" } }
                    Rectangle { id: r2; width: 100; height:  24; color: 'gray';   Text { text: "yyy" } }
                }
                ScrollBar {
                    orientation: Qt.Vertical
                    anchors {top: parent.top; right: parent.right; bottom: parent.bottom }
                }
            }
        }
        
        

        I get this:
        scrollbar.PNG

        Moving the scrollbar doesn't change the view. I'd expect eventually to get to the bottom of the yellow rectangle and see the gray one. How is that the scrollbar isn't affecting the contents of the Scrollview/Flickable (I've tried both)?

        Thanks...

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

        I got it working. There were a few things wrong with my original example, but the main problem was I needed to declare the scrollbar differently:

            Flickable {
                id: flickable
        
                Layout.fillHeight: true
                Layout.fillWidth: true
                clip: true
                contentHeight: equipmentGrid.height
        
                GridLayout {
                    id: equipmentGrid
                    ...
                }
        
                ScrollBar.vertical: ScrollBar {
                    policy: ScrollBar.AsNeeded
                }
            }
        }
        

        Once I got the scroll bar operational, I needed to add the "clip: true" in order to prevent the flickable from scrolling up over items above the GridLayout.

        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