Results 1 to 8 of 8

Thread: An unusual effect of a component over another in a QML program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2016
    Posts
    76
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows Android

    Default An unusual effect of a component over another in a QML program

    Hi all,

    I tested the QML program below on an Android device (a tablet running Android 4.4.2). The problem is that, when rackets are not moving the ball moves smoothly (and it’s OK), but when I move either racket, it affects the speed of the ball, strangely, and reduces ball's speed! These two must be independent in terms of movement and speed, but in effect this issue takes place. I don’t know why.

    Will you if possible test this code on your Android device too, to see if the problem exits there as well? If yes, what could be the source of the issue and how to remedy that, please?

    main.qml:

    Qt Code:
    1. import QtQuick 2.12
    2. import QtQuick.Window 2.12
    3. import QtQuick.Controls 2.5
    4.  
    5. Window {
    6. id: window
    7. visible: true
    8. width: 1000; height: 800
    9. color: "gray"
    10.  
    11. // The components
    12. // --------------
    13.  
    14. Rectangle {
    15. id: table
    16. anchors.fill: parent
    17. anchors.margins: 10
    18. y: 10
    19. anchors.horizontalCenter: parent.horizontalCenter
    20. color: "royalblue"
    21. }
    22. Racket {
    23. id: blackRacket
    24. anchors.left: table.left
    25. anchors.leftMargin: width * 2
    26. y: table.height / 2
    27. color: "black"
    28. }
    29. Racket {
    30. id: redRacket
    31. anchors.right: table.right
    32. anchors.rightMargin: width * 2
    33. y: table.height / 2
    34. color: "red"
    35. }
    36. Ball {
    37. id: ball
    38. x: 150
    39. y: 150
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 


    Ball.qml:

    Qt Code:
    1. import QtQuick 2.12
    2.  
    3. Rectangle {
    4. width: 18; height: 18
    5. color: "white"
    6. radius: width/2
    7.  
    8. Timer { // This timer's job is merely moving the ball
    9. id: timer
    10. interval: 22; repeat: true; running: true
    11.  
    12. onTriggered: {
    13. parent.x += 0.88
    14. parent.y += 0.88
    15. }
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    Racket.qml:

    Qt Code:
    1. import QtQuick 2.12
    2.  
    3. Rectangle {
    4. id: root
    5. width: 15; height: 65
    6.  
    7. MouseArea {
    8. anchors.fill: root
    9.  
    10. drag.target: root
    11. drag.axis: Drag.YAxis
    12. drag.minimumY: table.y
    13. drag.maximumY: table.height - root.height - 10
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

  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: An unusual effect of a component over another in a QML program

    Most likely the timer event processing is delayed by user input processing, so the spacing becomes more than 22ms.

    Two ideas:

    1) instead of using a timer, calculate the duration needed for the whole movement and use an animation (or a pair of animations) to control the actual movement

    2) Instead of assuming mono spaced time events, take the current time stamp in onTriggered, calculate how much time has really elapsed since the last invocation and adjust the position accordingly

    Cheers,
    _

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

    franky (5th February 2019)

Similar Threads

  1. which component to disable to reduce the size of program?
    By umnbr in forum Installation and Deployment
    Replies: 3
    Last Post: 11th February 2016, 10:09
  2. QDockWidget unusual layout
    By Kryzon in forum Newbie
    Replies: 2
    Last Post: 24th October 2014, 03:10
  3. Replies: 8
    Last Post: 31st October 2011, 02:49
  4. Unusual TableView
    By giker in forum Qt Programming
    Replies: 0
    Last Post: 6th January 2011, 14:10
  5. Getting some unusual character
    By Abc in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2008, 07:28

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.