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. GridView, how to position the view at startup?
Forum Updated to NodeBB v4.3 + New Features

GridView, how to position the view at startup?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 364 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.
  • MesrineM Offline
    MesrineM Offline
    Mesrine
    wrote on last edited by Mesrine
    #1

    Hello everyone,

    I do not know how to set the position of the view when the Gridview becomes visible.

    As an example, the following code.qml:

    import QtQuick.Layouts
    import QtQuick.Controls
    import QtQuick
    import QtQml
    
    
    ColumnLayout
    {
        RowLayout
        {
            Layout.fillWidth: true
            SpinBox {
                id:spin
                value: 0
                from:0
                to:yearSelector.count-1
                onValueModified:
                {
                    yearSelector.positionViewAtIndex(spin.value, GridView.Beginning)
                }
            }
        }
    
        GridView {
            id:yearSelector
            Layout.fillHeight: true
            Layout.fillWidth: true
            model:     ListModel {
    
                ListElement {year:0}
                ListElement {year:1}
                ListElement {year:2}
                ListElement {year:3}
                ListElement {year:4}
                ListElement {year:5}
                ListElement {year:6}
                ListElement {year:7}
                ListElement {year:8}
                ListElement {year:9}
                ListElement {year:10}
                ListElement {year:11}
                ListElement {year:12}
                ListElement {year:13}
                ListElement {year:14}
                ListElement {year:15}
                ListElement {year:16}
                ListElement {year:17}
                ListElement {year:18}
                ListElement {year:19}
    
            }
            cellWidth:yearSelector.width*0.3333
            cellHeight:yearSelector.height*0.5
            //currentIndex :15
            Component.onCompleted: yearSelector.positionViewAtIndex(15, GridView.Beginning)
    
            delegate:Button {
                text:year
            }
    
    
        }
    
    }
    
    

    shows a GridView with 20 Buttons. The grid view has 3 columns and 7 rows and shows 2 rows at a time.

    I was thinking that setting currentIndex :15 will show in the view the button with text= 15 at startup, but this does not work.
    Also, when calling Component.onCompleted: yearSelector.positionViewAtIndex(15, GridView.Beginning)
    does not show the button with text =15 at startup.

    If I change the spinBox value to 15 the GridView shows the button with text =15.

    I am testing the type like

    ~/Qt/6.7.0/gcc_64/bin/qml code.qml
    

    Is this a bug in GridView or i am doing something wrong?
    Many thanks for your time.

    jeremy_kJ 1 Reply Last reply
    0
    • MesrineM Mesrine

      Hello everyone,

      I do not know how to set the position of the view when the Gridview becomes visible.

      As an example, the following code.qml:

      import QtQuick.Layouts
      import QtQuick.Controls
      import QtQuick
      import QtQml
      
      
      ColumnLayout
      {
          RowLayout
          {
              Layout.fillWidth: true
              SpinBox {
                  id:spin
                  value: 0
                  from:0
                  to:yearSelector.count-1
                  onValueModified:
                  {
                      yearSelector.positionViewAtIndex(spin.value, GridView.Beginning)
                  }
              }
          }
      
          GridView {
              id:yearSelector
              Layout.fillHeight: true
              Layout.fillWidth: true
              model:     ListModel {
      
                  ListElement {year:0}
                  ListElement {year:1}
                  ListElement {year:2}
                  ListElement {year:3}
                  ListElement {year:4}
                  ListElement {year:5}
                  ListElement {year:6}
                  ListElement {year:7}
                  ListElement {year:8}
                  ListElement {year:9}
                  ListElement {year:10}
                  ListElement {year:11}
                  ListElement {year:12}
                  ListElement {year:13}
                  ListElement {year:14}
                  ListElement {year:15}
                  ListElement {year:16}
                  ListElement {year:17}
                  ListElement {year:18}
                  ListElement {year:19}
      
              }
              cellWidth:yearSelector.width*0.3333
              cellHeight:yearSelector.height*0.5
              //currentIndex :15
              Component.onCompleted: yearSelector.positionViewAtIndex(15, GridView.Beginning)
      
              delegate:Button {
                  text:year
              }
      
      
          }
      
      }
      
      

      shows a GridView with 20 Buttons. The grid view has 3 columns and 7 rows and shows 2 rows at a time.

      I was thinking that setting currentIndex :15 will show in the view the button with text= 15 at startup, but this does not work.
      Also, when calling Component.onCompleted: yearSelector.positionViewAtIndex(15, GridView.Beginning)
      does not show the button with text =15 at startup.

      If I change the spinBox value to 15 the GridView shows the button with text =15.

      I am testing the type like

      ~/Qt/6.7.0/gcc_64/bin/qml code.qml
      

      Is this a bug in GridView or i am doing something wrong?
      Many thanks for your time.

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      With a few minor changes to give the window a reasonable size and to some sort of rendering issue, the view starts with index 15 in the upper left corner on my macOS, Qt 6.5.3 installation. This may be a recently introduced bug.

      Does the GridView.count property reflect the expected value?

      Asking a question about code? http://eel.is/iso-c++/testcase/

      MesrineM 1 Reply Last reply
      0
      • jeremy_kJ jeremy_k

        With a few minor changes to give the window a reasonable size and to some sort of rendering issue, the view starts with index 15 in the upper left corner on my macOS, Qt 6.5.3 installation. This may be a recently introduced bug.

        Does the GridView.count property reflect the expected value?

        MesrineM Offline
        MesrineM Offline
        Mesrine
        wrote on last edited by Mesrine
        #3

        @jeremy_k

        if I do

        Component.onCompleted:
                {
                    console.log(yearSelector.count);
                    yearSelector.positionViewAtIndex(15, GridView.Beginning)
        
                }
        

        It prints 20 as expected;
        Also, I tried with ~/Qt/6.5.3/gcc_64/bin/qml code.qml and got the same results, what did you change?

        jeremy_kJ 1 Reply Last reply
        0
        • MesrineM Mesrine

          @jeremy_k

          if I do

          Component.onCompleted:
                  {
                      console.log(yearSelector.count);
                      yearSelector.positionViewAtIndex(15, GridView.Beginning)
          
                  }
          

          It prints 20 as expected;
          Also, I tried with ~/Qt/6.5.3/gcc_64/bin/qml code.qml and got the same results, what did you change?

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by jeremy_k
          #4
          import QtQuick.Layouts
          import QtQuick.Controls
          import QtQuick
          
          ColumnLayout
          {
              width: 300
              height: 600
              SpinBox {
                  from:0
                  to:yearSelector.count-1
                  onValueModified: yearSelector.positionViewAtIndex(value, GridView.Beginning)
              }
          
              GridView {
                  id:yearSelector
                  Layout.fillHeight: true
                  Layout.fillWidth: true
                  model: 20
                  cellWidth: width / 3
                  cellHeight: height / 2
                  Component.onCompleted: yearSelector.positionViewAtIndex(15, GridView.Beginning)
          
                  delegate: Text { text: index }
              }
          }
          

          My setup (hardware, OS, applications, etc) seems to be particularly sensitive to contrast changes, leading to unreadable highlights and text in some applications. I don't think that the changes mentioned above are altering the behavior, but it's worth trying.

          Asking a question about code? http://eel.is/iso-c++/testcase/

          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