Results 1 to 3 of 3

Thread: Catch mouse click to hide item

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

    Default Catch mouse click to hide item

    Hi,

    I'm having problem catching the outside click of my custom combobox item to hide the dropdown.
    Any help is greatly appreciated. TIA.

    CustomComboBox.qml
    Qt Code:
    1. FocusScope
    2. {
    3.  
    4. MouseArea
    5. {
    6. id: mouseArea
    7. anchors.fill: container
    8. onClicked: { container.focus = true; toggle() }
    9. onExited: close()
    10. }
    11.  
    12. Rectangle
    13. {
    14. id: dropDown
    15. // some codes for ListView to delegate list items
    16. states: [
    17. State {
    18. name: "visible";
    19. PropertyChanges { target: dropDown; height: container.height * listView.count }
    20. }
    21. ]
    22. }
    23.  
    24. function toggle() {
    25. if (dropDown.state === "visible") { close(false) } else { open() }
    26. }
    27.  
    28. function open() {
    29. dropDown.state = "visible"
    30. }
    31.  
    32. function close(update) {
    33. dropDown.state = ""
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 

    Main.qml
    Qt Code:
    1. Rectangle
    2. {
    3. CustomComboBox
    4. {
    5. id: textCmb
    6. }
    7.  
    8. Mousearea
    9. {
    10. onClicked: // here i'm having problem hiding the dropdown of textCmb
    11.  
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    *PS: I have many comboBoxes on main.qml

  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: Catch mouse click to hide item

    When you show the popup, make it a child of a MouseArea item which covers the whole screen/window. Catch clicks on this mouse area and hide the popup.
    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:

    joko (10th 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: Catch mouse click to hide item

    Quote Originally Posted by wysota View Post
    When you show the popup, make it a child of a MouseArea item which covers the whole screen/window. Catch clicks on this mouse area and hide the popup.
    As always, you're the best!

Similar Threads

  1. Replies: 6
    Last Post: 20th July 2012, 22:50
  2. Replies: 2
    Last Post: 16th July 2012, 12:40
  3. Catch click Hyperlink event
    By summer_of_69 in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2009, 19:43
  4. Catch item changed
    By nina1983 in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2008, 14:40
  5. Catch click/unclick event on QMainWindow border
    By thomaspu in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2008, 23:09

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.