Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?
Qt 6.11 is out! See what's new in the release blog

Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
12 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mirro
    wrote on last edited by mirro
    #1
    import QtQuick 2.9
    import QtQuick.Controls 2.3
    import QtQuick.Window 2.2
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 640
        title: qsTr("Hello World")
        id:root
        //
        Item{
                id:rctContains
                x:5
                y:5
                width:95
                height:95
        }
        Rectangle {
               id:testRct
               x:200
               y:0
               width:100
               height:100  
               visible:false
       }
        Rectangle {
            id:rct
            x:0
            y:0
            width: 100
            height: 100
            color: "green"
           //
            MouseArea {
                anchors.fill: parent   
                acceptedButtons: Qt.LeftButton | Qt.RightButton
                onPositionChanged:{
                            if(rctContains.contains(Qt.point(mouse.x,mouse.y ))
                            {
                                      testRct.visible = true
                           }
                            else       
                            {
                                       testRct.visible = false
                            }    
                  }
                onExited: {
    
                }    
            }    
        }
    ODБOïO 1 Reply Last reply
    0
    • M mirro

      @LeLev
      After I add a MouseArea to each sub menu.then, how do I tell if the mouse has left all the submenus?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #10

      @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

      mouse has left all the submenus?

      checking containsMouse property for every mousearea

      M 2 Replies Last reply
      0
      • M mirro
        import QtQuick 2.9
        import QtQuick.Controls 2.3
        import QtQuick.Window 2.2
        
        ApplicationWindow {
            visible: true
            width: 640
            height: 640
            title: qsTr("Hello World")
            id:root
            //
            Item{
                    id:rctContains
                    x:5
                    y:5
                    width:95
                    height:95
            }
            Rectangle {
                   id:testRct
                   x:200
                   y:0
                   width:100
                   height:100  
                   visible:false
           }
            Rectangle {
                id:rct
                x:0
                y:0
                width: 100
                height: 100
                color: "green"
               //
                MouseArea {
                    anchors.fill: parent   
                    acceptedButtons: Qt.LeftButton | Qt.RightButton
                    onPositionChanged:{
                                if(rctContains.contains(Qt.point(mouse.x,mouse.y ))
                                {
                                          testRct.visible = true
                               }
                                else       
                                {
                                           testRct.visible = false
                                }    
                      }
                    onExited: {
        
                    }    
                }    
            }
        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #2

        @mirro hi
        what are you trying to achieve?

        M 1 Reply Last reply
        0
        • ODБOïO ODБOï

          @mirro hi
          what are you trying to achieve?

          M Offline
          M Offline
          mirro
          wrote on last edited by
          #3

          @LeLev

          I want to achieve the mouse has left the area hidden testRct control in MouseArea::onPositionChanged()

          ODБOïO 1 Reply Last reply
          0
          • M mirro

            @LeLev

            I want to achieve the mouse has left the area hidden testRct control in MouseArea::onPositionChanged()

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by ODБOï
            #4

            @mirro

            Window {
                id: appWindow
                width: 512
                height: 512
                visible: true
               
                Rectangle{
                    width: 100
                    height: 100
                    color: "green"
                    MouseArea{
                        id: mouseGreen
                        anchors.fill: parent
                        hoverEnabled: true
                    }
                }
                
                Rectangle {
                    id:testRct
                    anchors.centerIn: parent
                    width:100
                    height:100
                    color : "red"
                    visible:mouseGreen.containsMouse
                }
            }
            
            M 1 Reply Last reply
            0
            • ODБOïO ODБOï

              @mirro

              Window {
                  id: appWindow
                  width: 512
                  height: 512
                  visible: true
                 
                  Rectangle{
                      width: 100
                      height: 100
                      color: "green"
                      MouseArea{
                          id: mouseGreen
                          anchors.fill: parent
                          hoverEnabled: true
                      }
                  }
                  
                  Rectangle {
                      id:testRct
                      anchors.centerIn: parent
                      width:100
                      height:100
                      color : "red"
                      visible:mouseGreen.containsMouse
                  }
              }
              
              M Offline
              M Offline
              mirro
              wrote on last edited by
              #5

              @LeLev Thank you.

              There's a situation, I'm going to implement a function in the MouseArea of the control.Rectangle to hide the control.Rectangle when the mouse leaves.

              However, there are Multiple child control.Rectangle on the control.Rectangle, how to avoid when the mouse moves to the child control.Rectangle, the control.Rectangle does not hide.

              My idea was to figure out where the mouse was in the area of ‘rctContains’ to solve this problem, but the mouse would fail if it moved too fast.

              I don't know if you have a solution.

              import QtQuick 2.9
              import QtQuick.Controls 2.3
              import QtQuick.Window 2.2
              
              ApplicationWindow {
                  visible: true
                  width:  640
                  height: 640
                  title:  qsTr("Hello World")
                  id:root
                  //
                  Item{
              		id:rctContains
              		x:5
              		y:5
              		width:95
              		height:95
                  }
              
                  Rectangle {
                      id:rct
                      x:0
                      y:0
                      width: 100
                      height: 100
                      color: "green"
              
              		Rectangle{
              		   id:subRct
              		   x:25
              		   y:25
              		   width:50
              		   height:50  
              		   visible:false
              	    }
              		
              		Rectangle{
              		   id:subRct2
              		   x:25
              		   y:50
              		   width:75
              		   height:75  
              		   visible:false
              	    }
              		
                      MouseArea {
                          anchors.fill: parent   
                          acceptedButtons: Qt.LeftButton | Qt.RightButton
                          onPositionChanged:{
              				if(rctContains.contains(Qt.point(mouse.x,mouse.y ))
              				{
              					rct.visible = true
              			    }
              				else       
              				{
              					rct.visible = false
              				}    
                          }
                          onExited:{
              
                          }    
                      }    
                  }
              }
              
              ODБOïO 1 Reply Last reply
              0
              • M mirro

                @LeLev Thank you.

                There's a situation, I'm going to implement a function in the MouseArea of the control.Rectangle to hide the control.Rectangle when the mouse leaves.

                However, there are Multiple child control.Rectangle on the control.Rectangle, how to avoid when the mouse moves to the child control.Rectangle, the control.Rectangle does not hide.

                My idea was to figure out where the mouse was in the area of ‘rctContains’ to solve this problem, but the mouse would fail if it moved too fast.

                I don't know if you have a solution.

                import QtQuick 2.9
                import QtQuick.Controls 2.3
                import QtQuick.Window 2.2
                
                ApplicationWindow {
                    visible: true
                    width:  640
                    height: 640
                    title:  qsTr("Hello World")
                    id:root
                    //
                    Item{
                		id:rctContains
                		x:5
                		y:5
                		width:95
                		height:95
                    }
                
                    Rectangle {
                        id:rct
                        x:0
                        y:0
                        width: 100
                        height: 100
                        color: "green"
                
                		Rectangle{
                		   id:subRct
                		   x:25
                		   y:25
                		   width:50
                		   height:50  
                		   visible:false
                	    }
                		
                		Rectangle{
                		   id:subRct2
                		   x:25
                		   y:50
                		   width:75
                		   height:75  
                		   visible:false
                	    }
                		
                        MouseArea {
                            anchors.fill: parent   
                            acceptedButtons: Qt.LeftButton | Qt.RightButton
                            onPositionChanged:{
                				if(rctContains.contains(Qt.point(mouse.x,mouse.y ))
                				{
                					rct.visible = true
                			    }
                				else       
                				{
                					rct.visible = false
                				}    
                            }
                            onExited:{
                
                            }    
                        }    
                    }
                }
                
                ODБOïO Offline
                ODБOïO Offline
                ODБOï
                wrote on last edited by
                #6

                @mirro sorry i'm not sure i understand what do you mean..
                And what is control.Rectangle ?
                Could you explain more generally what are your trying to achieve ?
                Note you can attach a MouseArea to every rectangle if you need
                Your MouseArea is on the Rectangle rct if you hide it you will never be able to hover it again.

                Are you trying to make some kind of drop down menu ?

                M 1 Reply Last reply
                0
                • ODБOïO ODБOï

                  @mirro sorry i'm not sure i understand what do you mean..
                  And what is control.Rectangle ?
                  Could you explain more generally what are your trying to achieve ?
                  Note you can attach a MouseArea to every rectangle if you need
                  Your MouseArea is on the Rectangle rct if you hide it you will never be able to hover it again.

                  Are you trying to make some kind of drop down menu ?

                  M Offline
                  M Offline
                  mirro
                  wrote on last edited by mirro
                  #7

                  @LeLev control.Rectangle is mean QML.Control.Rectangle.

                  Yes, I want to hide the drop-down menu when the mouse leaves the rectangular area of the drop-down menu.

                  However, there is a problem. the drop-down menu hide when the mouse moves to the menuItem,

                  I don't know if you have a solution.

                  ODБOïO 1 Reply Last reply
                  0
                  • M mirro

                    @LeLev control.Rectangle is mean QML.Control.Rectangle.

                    Yes, I want to hide the drop-down menu when the mouse leaves the rectangular area of the drop-down menu.

                    However, there is a problem. the drop-down menu hide when the mouse moves to the menuItem,

                    I don't know if you have a solution.

                    ODБOïO Offline
                    ODБOïO Offline
                    ODБOï
                    wrote on last edited by ODБOï
                    #8

                    @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

                    control.Rectangle is mean QML.Control.Rectangle.

                    Still not sure what do you mean by that.. but lets just ignore this.

                    @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

                    Yes, I want to hide the drop-down menu when the mouse leaves the rectangular area of the drop-down menu.

                    That should be part of your initial question..

                    as i suggested before, add a MouseArea to each sub menu so you can test if there is one that contains mouse
                    or use Menu
                    https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-menu

                    M 1 Reply Last reply
                    0
                    • ODБOïO ODБOï

                      @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

                      control.Rectangle is mean QML.Control.Rectangle.

                      Still not sure what do you mean by that.. but lets just ignore this.

                      @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

                      Yes, I want to hide the drop-down menu when the mouse leaves the rectangular area of the drop-down menu.

                      That should be part of your initial question..

                      as i suggested before, add a MouseArea to each sub menu so you can test if there is one that contains mouse
                      or use Menu
                      https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-menu

                      M Offline
                      M Offline
                      mirro
                      wrote on last edited by
                      #9

                      @LeLev
                      After I add a MouseArea to each sub menu.then, how do I tell if the mouse has left all the submenus?

                      ODБOïO 1 Reply Last reply
                      0
                      • M mirro

                        @LeLev
                        After I add a MouseArea to each sub menu.then, how do I tell if the mouse has left all the submenus?

                        ODБOïO Offline
                        ODБOïO Offline
                        ODБOï
                        wrote on last edited by
                        #10

                        @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

                        mouse has left all the submenus?

                        checking containsMouse property for every mousearea

                        M 2 Replies Last reply
                        0
                        • ODБOïO ODБOï

                          @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

                          mouse has left all the submenus?

                          checking containsMouse property for every mousearea

                          M Offline
                          M Offline
                          mirro
                          wrote on last edited by
                          #11

                          @LeLev

                          How to determine when the mouse leaves the Menu area to turn off Menu?

                          MenuItem is the topmost window, so it is impossible to determine if the mouse has left the Menu area.

                          import QtQuick 2.6
                          import QtQuick.Controls 2.1
                          Item{
                          	//
                          	function openMenu()
                          	{
                          		menu.open()
                          	}
                          	function closeMenu()
                          	{
                          		menu.close()
                          	}
                          	
                          	Menu {
                          		id: menu
                          		background: Rectangle {
                          			implicitWidth: 200
                          			implicitHeight: 200
                          			color: "#ffffff"
                          			border.color: "#353637"
                          		}
                          	
                          		MenuItem {
                          			text: qsTr("New...")
                          		}
                          		MenuItem {
                          			text: qsTr("Open...")
                          		}
                          		MenuItem {
                          			text: qsTr("Save")
                          		}
                          	
                          		MouseArea {
                          			anchors.fill: parent
                          			acceptedButtons: Qt.LeftButton | Qt.RightButton
                          			onExited: {
                          				menu.close()
                          			}
                          		}
                          	}
                          }
                          
                          1 Reply Last reply
                          0
                          • ODБOïO ODБOï

                            @mirro said in Why does MouseArea sometimes determine that the mouse left the rectangular area to hide QML.Control is not successful?:

                            mouse has left all the submenus?

                            checking containsMouse property for every mousearea

                            M Offline
                            M Offline
                            mirro
                            wrote on last edited by
                            #12

                            @LeLev

                            How can Checking start a timer containsMouse property for every MouseArea?

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved