Results 1 to 3 of 3

Thread: GridView in a ScrollView hangs when window is resized (cell width depends on window w

  1. #1
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default GridView in a ScrollView hangs when window is resized (cell width depends on window w

    Hi,

    I have a QML code to show a GridView in a ScrollView, with grid cells width depending on the ScrollView width.

    When I resize quickly the window, to change the width, it hangs. It happens when the scroll appears/disappears, since the width changes

    I see a warning in the output: QML GridView: Binding loop detected for property "cellHeight"

    I hope anyone could tell me the problem. It is clearly a loop related with the cells width, but I can not find it..

    My code:

    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.3
    3.  
    4. Item {
    5. width: 400
    6. height: 400
    7.  
    8. Text {
    9. id: header
    10. anchors { top: parent.top; topMargin: 20; horizontalCenter: parent.horizontalCenter }
    11. text: "Header"
    12. }
    13.  
    14. ScrollView {
    15.  
    16. id: scrollGrid
    17.  
    18. anchors{ top: header.bottom; topMargin: 40; bottom: parent.bottom; bottomMargin: 20; left: parent.left; right: parent.right }
    19.  
    20. GridView {
    21. id: grid
    22.  
    23. anchors{ top: parent.top; left: parent.left; right: parent.right}
    24.  
    25. height: parent.height
    26.  
    27. model: fruitModel
    28.  
    29. cellHeight: grid.width/3
    30. cellWidth: grid.width/3
    31.  
    32. visible: scrollGrid.visible
    33.  
    34. delegate: Rectangle {
    35. width: grid.cellWidth; height: grid.cellHeight
    36. Text {
    37. anchors.fill: parent
    38. text: name
    39. verticalAlignment: Text.AlignVCenter; horizontalAlignment: Text.AlignHCenter
    40. }
    41. border.width: 1
    42. }
    43. }
    44. }
    45.  
    46. ListModel {
    47. id: fruitModel
    48.  
    49. ListElement { name: "Apple" }
    50. ListElement { name: "Orange" }
    51. ListElement { name: "Banana" }
    52. ListElement { name: "Banana1" }
    53. ListElement { name: "Banana2" }
    54. ListElement { name: "Banana3" }
    55. ListElement { name: "Banana4" }
    56. ListElement { name: "Banana5" }
    57. ListElement { name: "Banana6" }
    58. ListElement { name: "Banana7" }
    59. ListElement { name: "Banana8" }
    60. ListElement { name: "Banana9" }
    61. ListElement { name: "Banana0" }
    62. ListElement { name: "Ban2ana" }
    63. ListElement { name: "Ban3ana" }
    64. ListElement { name: "Ban4ana" }
    65. ListElement { name: "Ban5ana" }
    66. ListElement { name: "Ban6ana" }
    67. ListElement { name: "Ban7ana" }
    68. ListElement { name: "Ban8ana" }
    69. }
    70. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ddonate; 14th October 2016 at 09:49.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: GridView in a ScrollView hangs when window is resized (cell width depends on wind

    Not sure why this would be a binding loop, but maybe it is just wrongly detected as such.

    Two ideas you could try

    1) Don't bind to the width, but react to width change
    Qt Code:
    1. onWidthChanged: cellWidth = width / 3
    2. cellHeight: cellWidth
    To copy to clipboard, switch view to plain text mode 

    2) Bind to some other item's withd
    Qt Code:
    1. cellWidth: scrollGrid.viewport.width
    2. cellHeight: cellWidth
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GridView in a ScrollView hangs when window is resized (cell width depends on wind

    Thanks anda_skoa for your help,

    I have tried both ideas but no success, it still hangs when resizing the window...

Similar Threads

  1. Replies: 4
    Last Post: 14th July 2016, 14:03
  2. Replies: 2
    Last Post: 26th May 2016, 02:07
  3. Replies: 6
    Last Post: 9th November 2011, 04:31
  4. Replies: 2
    Last Post: 29th June 2011, 14:24
  5. QMdiSubWindow problem with resized window
    By estanisgeyer in forum Qt Programming
    Replies: 2
    Last Post: 7th January 2008, 14:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.