qt - How to catch the moment when QML Component is completely layouted? -


i have gridview in qml applicationwindow should filled items.

i place items js function "placeitems". problem when component.oncreated signal of applicationwindow called gridview not yet layouted. example, gridview has x coordinate equal -425 in component.oncreated of applicationwindow. if call same function second later - ok , gridview has correct coordinates (=75).

i've check qt reference , forth , haven't found other signals (something onlayouted or onlayoutcomplete) may helpful. question when call "placeitems" gridview in applicationwindow has correct coordinates?

update1: observe bad behaviour click file->start after application started. place item in correct place.

import qtquick 2.2 import qtquick.window 2.1 import qtquick.controls 1.1  applicationwindow {     id: mainwindow      width:1000     height: 900     color : "white"     visible: true     flags: qt.window      function max (a,b) { return a>b ? : b; }     function min (a,b) { return a<b ? : b; }      property int sizemin: width < height ? width : height      property int dimfield: sizemin - 50     property int dimcellspacing: 3     property int dimcell: (dimfield / 5 ) - 1 - dimcellspacing      gridview {         id: field         anchors.centerin: parent         model: 20          width: dimfield         height: dimfield          cellwidth: dimcell         cellheight: dimcell          delegate: cell          property var items: []          function centercell(column,row) {             return {x: field.x + (column + 0.5) * cellwidth,                 y: field.y + (row + 0.5) * cellheight}         }          function placeitem(name, col, row) {             var c = centercell(col,row)             items[name].centerx = c.x             items[name].centery = c.y         }          function placeitems() {             placeitem ("a", 3, 3)             //placeitem ("b", 4, 4)         }      }      component.oncompleted: field.placeitems()      component {         id: cell          rectangle {             id: rectcell              width: dimcell             height: dimcell             color: "lightgray"              border.width: 3             border.color: "brown"         }     }      rectangle     {         id: rectitema          property int dimitem: 100         property int centerx: 0         property int centery: 0         property int margin: 5         property var cell: field.items["a"] =         border.color: "black"         border.width: 3          width: dimitem         height: dimitem          x: centerx - width/2         y: centery - height/2          color: "red"         opacity: 0.5     }      menubar: menubar {         menu {             title: qstr("file")             menuitem {                 text: qstr("start")                 ontriggered: field.placeitems();             }             menuitem {                 text: qstr("exit")                 ontriggered: qt.quit();             }         }     } } 

    function placeitem(name, col, row) {         items[name].anchors.horizontalcenter = field.left;         items[name].anchors.verticalcenter = field.top;         items[name].anchors.horizontalcenteroffset = (col + 0.5) * cellwidth;         items[name].anchors.verticalcenteroffset = (row + 0.5) * cellheight;     } 

the key anchor element in grid view , move according calculations.

btw, know qml has built in functions math.min/math.max?

edit

or better yet, why not define bindings in rectitema directly?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -