Results 1 to 3 of 3

Thread: Qt Quick button mousearea issue

  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt Quick button mousearea issue

    Hi,

    This is a working code, i just want some advise:

    Button.qml
    Qt Code:
    1. Item
    2. {
    3. property alias text: label.text
    4. property bool pressed: false
    5.  
    6. property int btnHeight: Functions.buttonHeight
    7.  
    8. id: button
    9. height: btnHeight
    10.  
    11. Rectangle
    12. {
    13. id: rec
    14. anchors.fill: parent
    15. color: pressed ? "#226EEA" : "#1150B7"
    16. }
    17.  
    18. Text {
    19. id: label
    20. color: "white"
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    Otherfile.qml
    Qt Code:
    1. Button
    2. {
    3. id: doneBtn
    4. text: qsTr("Done")
    5.  
    6. MouseArea
    7. {
    8. anchors.fill: parent
    9. onClicked: {
    10. //some codes
    11. }
    12. onPressed: { doneBtn.pressed = true }
    13. onReleased: { doneBtn.pressed = false }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    Here are my questions:
    1. I'm having problem when I put a mouse area on Button.qml, it will be overriden by the mouse area set from other file. I wanted to put the onPressed and onReleased in Button.qml, so that I don't have to write it down in every mouse area of each buttons.
    2. I read somewhere that it is advisable not to put mouse area in reuseable elements, is that correct?
    3. Can you please advise how to revise the code, not exactly an actual code but some tips.

    TIA.

  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: Qt Quick button mousearea issue

    You could
    1) make the Button a MouseArea instead of Item
    2) Put a MouseArea into the button, add signals to your item and then call your signals from the internal mouse area.

    Mostly depends on whether you are OK with the code using the button having access to other MouseArea features.

    Cheers,
    _

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

    joko (21st November 2014)

  4. #3
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Quick button mousearea issue

    Quote Originally Posted by anda_skoa View Post
    You could
    1) make the Button a MouseArea instead of Item
    2) Put a MouseArea into the button, add signals to your item and then call your signals from the internal mouse area.

    Mostly depends on whether you are OK with the code using the button having access to other MouseArea features.

    Cheers,
    _
    Thanks for the advise anda_skoa!

Similar Threads

  1. How to make a such button? Need help quick
    By bcdurak in forum Newbie
    Replies: 3
    Last Post: 20th May 2013, 06:57
  2. MouseArea
    By Viper666 in forum Qt Quick
    Replies: 6
    Last Post: 10th January 2013, 13:30
  3. close button in twm - WM_DELETE_WINDOW issue
    By deepakn in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2011, 12:57
  4. issue about unregulated button
    By cherrydou in forum Newbie
    Replies: 2
    Last Post: 26th May 2008, 03:01

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.