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. [Solved]Something really strange while trying to navigate in Grid
QtWS25 Last Chance

[Solved]Something really strange while trying to navigate in Grid

Scheduled Pinned Locked Moved QML and Qt Quick
gridnavigationkeyboard
13 Posts 2 Posters 4.4k 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.
  • Z Zubalama
    8 Apr 2015, 11:56

    something really strange is happening with childat() I've no clue why but it begins really well then it just acts really strange I mean it selects random child griddy is Grid's Id have I found a bug guys?

    Keys.onPressed: {
            if(event.key===Qt.Key_Right){
                event.accepted=true
                griddy.childAt(index+=65,indexi+=0).focus=true
               }
            if(event.key===Qt.Key_Down){
                event.accepted=true
                griddy.childAt(index+=0,indexi+=65).focus=true
               }
        }
    

    Edited: Please use ``` (3 backticks) for code blocks - p3c0

    P Offline
    P Offline
    p3c0
    Moderators
    wrote on 9 Apr 2015, 06:23 last edited by
    #2

    @Zubalama childAt requires x and y coordinates. Are you sure you are passing the right coordinates ?

    157

    Z 1 Reply Last reply 9 Apr 2015, 09:00
    0
    • P p3c0
      9 Apr 2015, 06:23

      @Zubalama childAt requires x and y coordinates. Are you sure you are passing the right coordinates ?

      Z Offline
      Z Offline
      Zubalama
      wrote on 9 Apr 2015, 09:00 last edited by
      #3

      @p3c0 index:x
      index:y and I know for sure that every element is width:60... and height: 60 and spacing is 5
      and I tested it even in designer and coordinates are correct. Two days have passed still trying to figure out what's wrong

      P 1 Reply Last reply 9 Apr 2015, 09:32
      0
      • Z Zubalama
        9 Apr 2015, 09:00

        @p3c0 index:x
        index:y and I know for sure that every element is width:60... and height: 60 and spacing is 5
        and I tested it even in designer and coordinates are correct. Two days have passed still trying to figure out what's wrong

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 9 Apr 2015, 09:32 last edited by
        #4

        @Zubalama Maybe due to spacing the items are not found correctly.
        I made a similar code for testing. See if this is what you are trying to do:

        Grid {
            id: grid
            focus: true
            columns: 6
            spacing: 5
            Rectangle { color: focus ? "red" : "yellow"; width: 50; height: 50 }
            Rectangle { color: focus ? "red" : "green"; width: 50; height: 50 }
            Rectangle { color: focus ? "red" : "blue"; width: 50; height: 50 }
            Rectangle { color: focus ? "red" : "cyan"; width: 50; height: 50 }
            Rectangle { color: focus ? "red" : "magenta"; width: 50; height: 50 }
            Rectangle { color: focus ? "red" : "pink"; width: 50; height: 50 }
        
            property int index: 0
        
            Keys.onPressed: {
                if(event.key===Qt.Key_Right){
                    grid.childAt((index++)*55,0).focus=true
                }
            }
        }
        

        157

        Z 1 Reply Last reply 9 Apr 2015, 12:12
        0
        • P p3c0
          9 Apr 2015, 09:32

          @Zubalama Maybe due to spacing the items are not found correctly.
          I made a similar code for testing. See if this is what you are trying to do:

          Grid {
              id: grid
              focus: true
              columns: 6
              spacing: 5
              Rectangle { color: focus ? "red" : "yellow"; width: 50; height: 50 }
              Rectangle { color: focus ? "red" : "green"; width: 50; height: 50 }
              Rectangle { color: focus ? "red" : "blue"; width: 50; height: 50 }
              Rectangle { color: focus ? "red" : "cyan"; width: 50; height: 50 }
              Rectangle { color: focus ? "red" : "magenta"; width: 50; height: 50 }
              Rectangle { color: focus ? "red" : "pink"; width: 50; height: 50 }
          
              property int index: 0
          
              Keys.onPressed: {
                  if(event.key===Qt.Key_Right){
                      grid.childAt((index++)*55,0).focus=true
                  }
              }
          }
          
          Z Offline
          Z Offline
          Zubalama
          wrote on 9 Apr 2015, 12:12 last edited by
          #5

          @p3c0 you have only horizontal I have vertical and horizontal probably that's why?

          P 1 Reply Last reply 9 Apr 2015, 12:25
          0
          • Z Zubalama
            9 Apr 2015, 12:12

            @p3c0 you have only horizontal I have vertical and horizontal probably that's why?

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 9 Apr 2015, 12:25 last edited by
            #6

            @Zubalama Well then,

            Grid {
                id: grid
                focus: true
                columns: 3
                rows: 3
                spacing: 5
                Rectangle { color: focus ? "red" : "yellow"; width: 50; height: 50 }
                Rectangle { color: focus ? "red" : "green"; width: 50; height: 50 }
                Rectangle { color: focus ? "red" : "blue"; width: 50; height: 50 }
                Rectangle { color: focus ? "red" : "cyan"; width: 50; height: 50 }
                Rectangle { color: focus ? "red" : "magenta"; width: 50; height: 50 }
                Rectangle { color: focus ? "red" : "pink"; width: 50; height: 50 }
            
                property int xindex: -1
                property int yindex: 0
            
                Keys.onPressed: {
                    if(event.key===Qt.Key_Right) {
                        grid.childAt((++xindex)*55,yindex*55).focus=true
                    } else if(event.key===Qt.Key_Down) {
                        grid.childAt(xindex*55,(++yindex)*55).focus=true
                    }
                }
            }
            

            You can just change logic as per your need.

            157

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zubalama
              wrote on 9 Apr 2015, 13:00 last edited by
              #7

              I think you don't understand what's my problem I have 10 columns and 5 rows and they don't act the way they should not with spacing not even without. At first 20 navigation acts they they do well but after that they act more then strangely

              P 1 Reply Last reply 10 Apr 2015, 05:10
              0
              • Z Zubalama
                9 Apr 2015, 13:00

                I think you don't understand what's my problem I have 10 columns and 5 rows and they don't act the way they should not with spacing not even without. At first 20 navigation acts they they do well but after that they act more then strangely

                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 10 Apr 2015, 05:10 last edited by
                #8

                @Zubalama I still think it could be more like a logical issue. May be you should post the complete minimal code which will clearly indicate the problem.
                Did you take a look at GridView ? IMO, navigation in it is far more easier.

                157

                Z 2 Replies Last reply 10 Apr 2015, 05:28
                0
                • P p3c0
                  10 Apr 2015, 05:10

                  @Zubalama I still think it could be more like a logical issue. May be you should post the complete minimal code which will clearly indicate the problem.
                  Did you take a look at GridView ? IMO, navigation in it is far more easier.

                  Z Offline
                  Z Offline
                  Zubalama
                  wrote on 10 Apr 2015, 05:28 last edited by
                  #9

                  @p3c0 no I had just Grid gonna try GridView now

                  1 Reply Last reply
                  0
                  • P p3c0
                    10 Apr 2015, 05:10

                    @Zubalama I still think it could be more like a logical issue. May be you should post the complete minimal code which will clearly indicate the problem.
                    Did you take a look at GridView ? IMO, navigation in it is far more easier.

                    Z Offline
                    Z Offline
                    Zubalama
                    wrote on 10 Apr 2015, 06:36 last edited by
                    #10

                    @p3c0 I just realized that they begin acting strangely after focusing grid element for second time

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      Zubalama
                      wrote on 10 Apr 2015, 17:40 last edited by
                      #11

                      I realized now :/ I did +=that ruined it I should've done just +65 everything works properly now ty P3Co

                      P 1 Reply Last reply 11 Apr 2015, 09:47
                      0
                      • Z Zubalama
                        10 Apr 2015, 17:40

                        I realized now :/ I did +=that ruined it I should've done just +65 everything works properly now ty P3Co

                        P Offline
                        P Offline
                        p3c0
                        Moderators
                        wrote on 11 Apr 2015, 09:47 last edited by
                        #12

                        @Zubalama Good that you found it. Doesn't GridView fit in your scenario ?

                        157

                        Z 1 Reply Last reply 14 Apr 2015, 09:02
                        0
                        • P p3c0
                          11 Apr 2015, 09:47

                          @Zubalama Good that you found it. Doesn't GridView fit in your scenario ?

                          Z Offline
                          Z Offline
                          Zubalama
                          wrote on 14 Apr 2015, 09:02 last edited by
                          #13

                          @p3c0 it does yet I wanted to fix the problem I personally faced thanks for an advice

                          1 Reply Last reply
                          0

                          11/13

                          10 Apr 2015, 17:40

                          • Login

                          • Login or register to search.
                          11 out of 13
                          • First post
                            11/13
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved