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. check Hover in pool of rectangles
Forum Updated to NodeBB v4.3 + New Features

check Hover in pool of rectangles

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml canvashoverqt quickpopoveepopup
11 Posts 2 Posters 6.3k Views 2 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.
  • A Anas A. Ismail
    4 Nov 2015, 00:09

    Hello Everyone,
    I have main Canvas that contains a pool of rectangles I want to show a popup for each hovered rectangle, how could that possibly be done ?
    I always can check this with the last created one, but the taken action applied on all of other rectangles.

    P Offline
    P Offline
    p3c0
    Moderators
    wrote on 4 Nov 2015, 06:34 last edited by
    #2

    @Anas-A.-Ismail You can add MouseArea inside each Rectangle and set hoverEnabled property to true the when mouse is hovered over these rectangle onEntered event handler is triggerred. You can invoke a popup from there.

    157

    A 1 Reply Last reply 4 Nov 2015, 07:15
    0
    • P p3c0
      4 Nov 2015, 06:34

      @Anas-A.-Ismail You can add MouseArea inside each Rectangle and set hoverEnabled property to true the when mouse is hovered over these rectangle onEntered event handler is triggerred. You can invoke a popup from there.

      A Offline
      A Offline
      Anas A. Ismail
      wrote on 4 Nov 2015, 07:15 last edited by
      #3

      @p3c0 I'm drawing the rectangles dynamically at runtime, so when I hover on one of them, the action accepted from the last created rectangle.

      P 1 Reply Last reply 4 Nov 2015, 07:16
      0
      • A Anas A. Ismail
        4 Nov 2015, 07:15

        @p3c0 I'm drawing the rectangles dynamically at runtime, so when I hover on one of them, the action accepted from the last created rectangle.

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 4 Nov 2015, 07:16 last edited by
        #4

        @Anas-A.-Ismail Do you mean you are drawing rectangles with Canvas API's ?

        157

        A 1 Reply Last reply 4 Nov 2015, 07:27
        0
        • P p3c0
          4 Nov 2015, 07:16

          @Anas-A.-Ismail Do you mean you are drawing rectangles with Canvas API's ?

          A Offline
          A Offline
          Anas A. Ismail
          wrote on 4 Nov 2015, 07:27 last edited by
          #5

          @p3c0 I'm drawing rectangles using Mouse (Drag/Drop) on a Canvas, So I have multiple rectangles on the same Canvas which created dynamically on run time using createObject method, I need to deal with each rectangle separately, like this image here

          P 1 Reply Last reply 4 Nov 2015, 07:30
          0
          • A Anas A. Ismail
            4 Nov 2015, 07:27

            @p3c0 I'm drawing rectangles using Mouse (Drag/Drop) on a Canvas, So I have multiple rectangles on the same Canvas which created dynamically on run time using createObject method, I need to deal with each rectangle separately, like this image here

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 4 Nov 2015, 07:30 last edited by
            #6

            @Anas-A.-Ismail Trying to understand. Did you create Rectangle's using createObject ? In that case you can put MouseArea inside it as said earlier.

            157

            A 1 Reply Last reply 4 Nov 2015, 07:35
            0
            • P p3c0
              4 Nov 2015, 07:30

              @Anas-A.-Ismail Trying to understand. Did you create Rectangle's using createObject ? In that case you can put MouseArea inside it as said earlier.

              A Offline
              A Offline
              Anas A. Ismail
              wrote on 4 Nov 2015, 07:35 last edited by
              #7

              @p3c0 Yes I did that, but hover property applied only on the last created Rectangle, and when I hover on it the wanted action applied on all rectangles like this image, I want to apply this action on each rectangle separately without affecting the others.

              Thanks.

              P 1 Reply Last reply 4 Nov 2015, 07:40
              0
              • A Anas A. Ismail
                4 Nov 2015, 07:35

                @p3c0 Yes I did that, but hover property applied only on the last created Rectangle, and when I hover on it the wanted action applied on all rectangles like this image, I want to apply this action on each rectangle separately without affecting the others.

                Thanks.

                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 4 Nov 2015, 07:40 last edited by
                #8

                @Anas-A.-Ismail That's strange. Each Rectangle will have its own MouseArea and which will generate hover events for that particular Item only. Can you post the relevant code ?

                157

                A 1 Reply Last reply 4 Nov 2015, 07:44
                0
                • P p3c0
                  4 Nov 2015, 07:40

                  @Anas-A.-Ismail That's strange. Each Rectangle will have its own MouseArea and which will generate hover events for that particular Item only. Can you post the relevant code ?

                  A Offline
                  A Offline
                  Anas A. Ismail
                  wrote on 4 Nov 2015, 07:44 last edited by p3c0 11 Apr 2015, 07:46
                  #9

                  @p3c0
                  img.qml

                  Item{
                     Canvas{
                          id: mainCanvase
                          width: 640
                          height: 480
                          visible: true
                          anchors.fill: parent
                  //        layer.enabled: false
                          BoundingBox{
                              id: imgBox
                          }
                  
                          MouseArea{
                              property Rectangle boundingBox: null
                              property Component commentBox: null
                              id: mainCanvaseMouseArea
                              anchors.fill: parent
                  
                              onPressed: {
                                 var boundingBoxObj = imgBox.createObject (mainCanvase, {"x" :mouse.x, "y": mouse.y});
                                  boundingBox = boundingBoxObj;
                              }
                  
                              onReleased: {
                                  if((boundingBox.width >2) && (boundingBox.height > 2))
                                  {
                                      boundingBox.createCommentBox();
                                      mainCanvaseMouseArea.enabled = false;
                                  }
                                  else
                                  {
                                      boundingBox.destroy();
                                  }
                              }
                  
                              onPositionChanged: {
                                  boundingBox.width = (Math.abs (mouse.x - boundingBox.x));
                                  boundingBox.height = (Math.abs (mouse.y - boundingBox.y));
                              }
                          }
                      }
                  }
                  

                  boundingbox.qml

                  Component{
                      id: boundingBoxComponent
                  
                      Rectangle{
                          id: boundingBoxRect
                          objectName: "boundingBoxRect"
                          border.color: "red"
                          radius: 10
                          color: "transparent"
                          property color onHoverColor: "blue"
                          property color defaultColor: "red"
                          property bool isHovered: true
                          property Component commentBox: null
                  
                          function createCommentBox(){
                              commentBox = Qt.createComponent("commentBox.qml")
                              commentBox.createObject(boundingBoxRect,{"y": boundingBoxRect.height+5})
                          }
                  
                          MouseArea{
                              id: boundingBoxMouseArea
                              //properties
                              hoverEnabled: true
                              anchors.fill: parent
                  
                              //events
                              onEntered: {
                                  parent.border.color = onHoverColor;
                                  isHovered = true;
                              }
                              onExited: {
                                  parent.border.color = defaultColor;
                                  isHovered = false;
                              }
                          }
                      }
                  }
                  
                  P 1 Reply Last reply 4 Nov 2015, 07:52
                  0
                  • A Anas A. Ismail
                    4 Nov 2015, 07:44

                    @p3c0
                    img.qml

                    Item{
                       Canvas{
                            id: mainCanvase
                            width: 640
                            height: 480
                            visible: true
                            anchors.fill: parent
                    //        layer.enabled: false
                            BoundingBox{
                                id: imgBox
                            }
                    
                            MouseArea{
                                property Rectangle boundingBox: null
                                property Component commentBox: null
                                id: mainCanvaseMouseArea
                                anchors.fill: parent
                    
                                onPressed: {
                                   var boundingBoxObj = imgBox.createObject (mainCanvase, {"x" :mouse.x, "y": mouse.y});
                                    boundingBox = boundingBoxObj;
                                }
                    
                                onReleased: {
                                    if((boundingBox.width >2) && (boundingBox.height > 2))
                                    {
                                        boundingBox.createCommentBox();
                                        mainCanvaseMouseArea.enabled = false;
                                    }
                                    else
                                    {
                                        boundingBox.destroy();
                                    }
                                }
                    
                                onPositionChanged: {
                                    boundingBox.width = (Math.abs (mouse.x - boundingBox.x));
                                    boundingBox.height = (Math.abs (mouse.y - boundingBox.y));
                                }
                            }
                        }
                    }
                    

                    boundingbox.qml

                    Component{
                        id: boundingBoxComponent
                    
                        Rectangle{
                            id: boundingBoxRect
                            objectName: "boundingBoxRect"
                            border.color: "red"
                            radius: 10
                            color: "transparent"
                            property color onHoverColor: "blue"
                            property color defaultColor: "red"
                            property bool isHovered: true
                            property Component commentBox: null
                    
                            function createCommentBox(){
                                commentBox = Qt.createComponent("commentBox.qml")
                                commentBox.createObject(boundingBoxRect,{"y": boundingBoxRect.height+5})
                            }
                    
                            MouseArea{
                                id: boundingBoxMouseArea
                                //properties
                                hoverEnabled: true
                                anchors.fill: parent
                    
                                //events
                                onEntered: {
                                    parent.border.color = onHoverColor;
                                    isHovered = true;
                                }
                                onExited: {
                                    parent.border.color = defaultColor;
                                    isHovered = false;
                                }
                            }
                        }
                    }
                    
                    P Offline
                    P Offline
                    p3c0
                    Moderators
                    wrote on 4 Nov 2015, 07:52 last edited by p3c0 11 Apr 2015, 07:52
                    #10

                    @Anas-A.-Ismail According to your code property Rectangle boundingBox will always point to the last created or the latest created Item.

                    157

                    A 1 Reply Last reply 9 Nov 2015, 12:15
                    1
                    • P p3c0
                      4 Nov 2015, 07:52

                      @Anas-A.-Ismail According to your code property Rectangle boundingBox will always point to the last created or the latest created Item.

                      A Offline
                      A Offline
                      Anas A. Ismail
                      wrote on 9 Nov 2015, 12:15 last edited by
                      #11

                      @p3c0 Thank You, your answers were really helpful, it's solved.

                      1 Reply Last reply
                      0

                      11/11

                      9 Nov 2015, 12:15

                      • Login

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