Results 1 to 11 of 11

Thread: Drag clickable circles and their letters in x-direction

  1. #1
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Drag clickable circles and their letters in x-direction

    I have a two files (Circle.qml and Letter.qml). On click of the mousearea a circle is placed along with the text of letter, because the Circle.qml refers to the Letter.qml file. Now I want to move the letter in x-direction on drag of the Circle in x-direction. I have tried this with a timer using beneath code, but you can click different circles with their own letters; each of the circle/letter combinations have to be movable independently. Now sometimes the link between circle and letter is not made, and sometimes the same circle is linked with multiple letters causing all these letters of other circles to be moved in x-direction. My questions:
    - how can I get the program working as I described?
    - do I follow the right approach (for example using a timer)?
    - if not, which approach should I follow?


    Circle.qml
    Qt Code:
    1. Rectangle {
    2. id: circle
    3. x: ...
    4. y: ...
    5. radius: {
    6. //linkscoretoanalysis.source = "Letter.qml";
    7. Global.j++
    8. Global.scoretoanalysisXarray[Global.i] = circle.x+8;
    9. }
    10. MouseArea {
    To copy to clipboard, switch view to plain text mode 

    Letter.qml
    Qt Code:
    1. Text {
    2. id: letter
    3. x: ...
    4. y: ...
    5. text: {
    6. if(Global.i > 0){
    7. Global.i++
    8. }
    9. ...
    10. }
    11. MouseArea {
    12. onClicked: {
    13. mytimer.running = true;
    14. Global.timerbool = true;
    15. }
    16. Timer {
    17. id: mytimer
    18. interval: 1
    19. repeat: true
    20. running: true
    21. onTriggered: {
    22. letter.x = Global.scoretoanalysisXarray[Global.i];
    23.  
    24. if(Global.i < Global.j){
    25. Global.i=1
    26. Global.j=1
    27. console.log("if1");
    28. }
    29.  
    30. if(Global.timerbool == false){
    31. mytimer.running = false;
    32. }
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Drag clickable circles and their letters in x-direction

    You have all kinds of "Global" stuff in there, maybe some values from a "pragma library" JS file?

    If the letter is to be bound to a circle, why not just do that using anchors?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag clickable circles and their letters in x-direction

    Can you refer me to a website that explains using anchors on items in different files? Or provide some source? What I have now is

    Qt Code:
    1. Letter {
    2. id: myletter
    3. anchors.left: circle.right
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Drag clickable circles and their letters in x-direction

    e.g.

    javascript Code:
    1. Circle {
    2. Letter {
    3. anchors.left: parent.right
    4. anchors.verticalCenter: parent.verticalCenter
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag clickable circles and their letters in x-direction

    Wysota, where do I have to place that code?

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

    Default Re: Drag clickable circles and their letters in x-direction

    Wherever you want to declare a circle with a letter attached to it.
    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.


  7. #7
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag clickable circles and their letters in x-direction

    Obviously I cannot place it in Circle.qml or Letter.qml. Do I have to place it in main.qml? Given the clickable circles and their letters of my first post, where do I have to put the code in order to attach the letters to their circles on dragging?

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

    Default Re: Drag clickable circles and their letters in x-direction

    Maybe it's best if you again describe what exactly you want to achieve. Apparently I misunderstood you. Just please don't use code when explaining - just describe what your task is and how you intend to achieve it.
    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.


  9. #9
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag clickable circles and their letters in x-direction

    In Circle.qml there is a mousearea inside a rectangle (called circle) to be able to click several circles on the screen. In Letter.qml there is also such a mousearea to click text on the screen. There is used a Loader to put letters on the screen when a new circle is made; the letters belong to these circles and should be moved synchronous in x-direction on dragging the circles. Anda Skoa said I could best connect the letters with the circles using anchors. Now I'm asking how to use the anchors because the letters and circles are in different files and can be clicked on the screen dynamically.
    Thanks in advance.

  10. #10
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Using anchors to move objects in different files on drag

    In Circle.qml there is a mousearea inside a rectangle (called circle) to be able to click several circles on the screen. In Letter.qml there is also such a mousearea to click text (letters) on the screen. There is used a Loader to put letters on the screen when a new circle is made; the letters belong to these circles and should be moved synchronous in x-direction on dragging the circles. Maybe I could best connect the letters with the circles using anchors. But how to use the anchors? (the letters and circles are in different files and can be clicked on the screen dynamically.)
    Should I use Global variables and put
    import "... .js" as Global
    above the file?
    How should I use another approach using anchors?

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

    Default Re: Using anchors to move objects in different files on drag

    "Files" correspond to "types". What you want is to control "instances" so it doesn't matter which "files" their types had been declared in. What matters is where you create instances of those types as you need to operate on instances and not types. Have a look at Component element and its createObject() method.
    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.


Similar Threads

  1. [SOLVED] Different color letters in QComboBox entries
    By T4ng10r in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2014, 11:54
  2. uppercase letters in a QTextEdit
    By annitaz in forum Qt Programming
    Replies: 2
    Last Post: 6th July 2013, 09:34
  3. KDChart Axis and Circles
    By sastrian in forum General Programming
    Replies: 1
    Last Post: 20th April 2012, 05:10
  4. QregExp: matching accented letters
    By bred in forum Qt Programming
    Replies: 0
    Last Post: 4th January 2011, 11:48
  5. A collection of letters and numbers
    By NewLegend in forum Qt Programming
    Replies: 8
    Last Post: 8th September 2010, 20:44

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.