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. confining ListView to mainWindow margins

confining ListView to mainWindow margins

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

    Hi all -

    I'd like to code a display that shows some number of items horizontally. The cumulative length of the items sometimes will exceed the window width, so the user can just scroll by swiping to see the desired items.

    I'd like to confine my ListView to the margins established in my ApplicationWindow, but I don't seem to be able to do that.

    Here's the code:

    ApplicationWindow {
        id: mainWindow
        width: 640
        height: 480
        visible: true
        readonly property int margin: 32
        readonly property int gutter: 16
    
        ColumnLayout {
            anchors.fill: parent
            ListView {
                Layout.fillHeight: true
                width: mainWindow.width - (mainWindow.margin * 2)
                Layout.margins: mainWindow.margin
                Layout.alignment: Qt.AlignHCenter
                orientation: ListView.Horizontal
                spacing: mainWindow.gutter
                boundsBehavior: Flickable.StopAtBounds
                boundsMovement: Flickable.StopAtBounds
                model: 5 //listModel
                delegate: Rectangle {
                    height: 100
                    width: 200
                    color: 'lightblue'
                    border.width: 1
                }
            }
        }
    }
    

    And this is what I'm getting:
    listview.JPG

    How can I get the contents of the list not to overreach the margins of the ApplicationWindow?

    Thanks...

    sierdzioS 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I'd like to code a display that shows some number of items horizontally. The cumulative length of the items sometimes will exceed the window width, so the user can just scroll by swiping to see the desired items.

      I'd like to confine my ListView to the margins established in my ApplicationWindow, but I don't seem to be able to do that.

      Here's the code:

      ApplicationWindow {
          id: mainWindow
          width: 640
          height: 480
          visible: true
          readonly property int margin: 32
          readonly property int gutter: 16
      
          ColumnLayout {
              anchors.fill: parent
              ListView {
                  Layout.fillHeight: true
                  width: mainWindow.width - (mainWindow.margin * 2)
                  Layout.margins: mainWindow.margin
                  Layout.alignment: Qt.AlignHCenter
                  orientation: ListView.Horizontal
                  spacing: mainWindow.gutter
                  boundsBehavior: Flickable.StopAtBounds
                  boundsMovement: Flickable.StopAtBounds
                  model: 5 //listModel
                  delegate: Rectangle {
                      height: 100
                      width: 200
                      color: 'lightblue'
                      border.width: 1
                  }
              }
          }
      }
      

      And this is what I'm getting:
      listview.JPG

      How can I get the contents of the list not to overreach the margins of the ApplicationWindow?

      Thanks...

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Add this to your ListView:

      clip: true
      

      (Z(:^

      mzimmersM 1 Reply Last reply
      2
      • mzimmersM mzimmers has marked this topic as solved on
      • sierdzioS sierdzio

        Add this to your ListView:

        clip: true
        
        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @sierdzio of course - how silly of me. Thanks, @sierdzio.

        sierdzioS 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @sierdzio of course - how silly of me. Thanks, @sierdzio.

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Don't worry, everybody forgets about clip from time to time :D I've been bitten by this a lot myself.

          (Z(:^

          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