Results 1 to 4 of 4

Thread: Grid container and rectangle frame

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Grid container and rectangle frame

    Hello forum,

    I have declared a Grid item to position its children in grid formation. Then I have a Rectangle item to act as a frame as follows:

    Qt Code:
    1. Rectangle {
    2. id: rect
    3. color: "red"
    4. radius: 10
    5. opacity: 0.1
    6. border.color: "black"
    7. focus: true
    8. //the rectangle element
    9. //will fill the whole grid container
    10. anchors.fill: controlContainer
    11.  
    12. Keys.onPressed: {
    13. if(event.key === Qt.Key_F1)
    14. {
    15. console.log('Key F1 was pressed')
    16. event.accepted = true
    17. }
    18. }
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    I want to apply spring animation with the key press event . In that case do I have to apply animation to rectangle only or both ?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grid container and rectangle frame

    It depends what you want to move. If both elements then you have to apply the animation to controlContainer since rect will adjust to its geometry so it will follow the animation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    sajis997 (14th January 2015)

  4. #3
    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: Grid container and rectangle frame

    Or you put both into the same parent and move the parent.

    But you already ignored that option in the other thread.

    Cheers,
    _

  5. #4
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Grid container and rectangle frame

    I am moving the interface in the following manner. It is functional , but I am not sure though if it is indeed the efficient way to do it.

    Qt Code:
    1. Item {
    2. id: root
    3. width: 512; height: 512
    4.  
    5.  
    6. TessellationSceneItem
    7. {
    8. id: tessSceneItem
    9. }
    10.  
    11. Grid {
    12. id: controlContainer
    13. rows: 2
    14. columns: 2
    15. spacing: 8
    16. anchors.margins: 8
    17. focus: true
    18.  
    19. //initially hide the UI gridope
    20. x: -width
    21.  
    22. property bool shown: false
    23.  
    24. ...............................
    25.  
    26. //child elements are laid out here
    27.  
    28. ...............................
    29.  
    30. Behavior on x { SpringAnimation { spring: 1; damping: 0.1 } }
    31. Behavior on y { SpringAnimation { spring: 1; damping: 0.1 } }
    32.  
    33. }
    34.  
    35. Keys.onPressed: {
    36. if(event.key === Qt.Key_F1)
    37. {
    38. if(controlContainer.shown === true)
    39. {
    40. controlContainer.x = -controlContainer.width - 20
    41. controlContainer.shown = false
    42. }
    43. else
    44. {
    45. controlContainer.x = 0
    46. controlContainer.shown = true
    47. }
    48. event.accepted = true
    49. }
    50. else if(event.key === Qt.Key_Escape)
    51. {
    52. //THIS PART IS NOT WORKING
    53. Qt.quit()
    54. event.accepted = true
    55. }
    56. }
    57.  
    58.  
    59. Rectangle {
    60. id: rect
    61. color: "red"
    62. radius: 10
    63. opacity: 0.1
    64. border.color: "black"
    65. focus: true
    66. //the rectangle element
    67. //will fill the whole layout
    68. anchors.fill: controlContainer
    69. }
    70.  
    71.  
    72. }
    To copy to clipboard, switch view to plain text mode 


    One part of the code snippet is not working . I am trying to close the application with the Esc key press event. If I press the Esc key I get the following output:

    Qt Code:
    1. Signal QQmlEngine::quit() emitted, but no receivers connected to handle it.
    To copy to clipboard, switch view to plain text mode 

    Any idea how to deal with it?

Similar Threads

  1. Replies: 2
    Last Post: 25th December 2014, 15:15
  2. Replies: 2
    Last Post: 4th September 2014, 11:09
  3. Replies: 0
    Last Post: 1st February 2014, 16:35
  4. Make Grid of Rectangle
    By sagirahmed in forum Newbie
    Replies: 1
    Last Post: 8th October 2010, 06:59
  5. Quick ? about qSort(Container & container)
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2007, 11:20

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.