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. Horizontal ScrollBar not scrolling content in ListView

Horizontal ScrollBar not scrolling content in ListView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 183 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    For the life of me I cannot make heads or tails of this:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    
    Window {
        id: window
    
        visible: true
        width: 640
        height: 480
        title: qsTr("ListView Horizontal ScrollBar DelegateChooser")
    
        ListModel {
            id: listmodel
    
            ListElement {type:"one"; datas:"123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}
            ListElement {type:"two"; datas:"123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}
        }
    
        ListView {
            width: parent.width/4
            height: parent.height
    
            clip: true
            spacing: 1
    
            delegate: Rectangle {
                width: window.width
                height: 20
                color: "darkred"
                border.color: "red"
                border.width: 1
    
                Text {
                    text: datas
                    color: "white"
                }
            }
    
            model: listmodel
    
            ScrollBar.horizontal: ScrollBar{}
        }
    }
    

    The delegate item is wider than the ListView itself. Shouldn't the scrollbar the delegate being shown?

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      Add this to scroll:

      ScrollBar.vertical: ScrollBar {}
          ScrollBar.horizontal: ScrollBar {
              id: horizscrollbar
          }
      

      Also needs contentWidth to be set to largest contentItem. Found that to be tricky and didn't always work:

                         onCountChanged: {
                              var maxwidth = 0
                              for(var ind=0; ind<count; ++ind){
                                  var item = itemAtIndex(ind)
                                  if(item.width > maxwidth)
                                      maxwidth = item.width
                              }
                              contentWidth = maxwidth
      
                              console.log(contentWidth)
                          }
      

      C++ is a perfectly valid school of magic.

      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