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. Remove Circular Area from MouseArea and Rectangle
Forum Updated to NodeBB v4.3 + New Features

Remove Circular Area from MouseArea and Rectangle

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 1.2k Views
  • 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
    maxwell31
    wrote on last edited by maxwell31
    #1

    Hi,

    I want to create custom buttons which look like the two black rectangles in the following image:
    0_1565087006523_Screenshot from 2019-08-06 12-22-31.png

    However, the red circular area should not be removed from the rectangles, so that a background image would be visible and also the red area should not react to the mouse area of the buttons.

    How could this be accomplished?

    J.HilkJ 1 Reply Last reply
    0
    • M maxwell31

      Hi,

      I want to create custom buttons which look like the two black rectangles in the following image:
      0_1565087006523_Screenshot from 2019-08-06 12-22-31.png

      However, the red circular area should not be removed from the rectangles, so that a background image would be visible and also the red area should not react to the mouse area of the buttons.

      How could this be accomplished?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @maxwell31
      what do you have so far? Because, when you create the Cycle after the rectangles, the circle should overlap and the mouseare underneath should not get the mouse events.

      And if they do , you could give the circle a mouse area of its own and simply do nothing with it 😉


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by
        #3

        I have nothing yet, this is just a graphical sketch. The problem is, that sometimes the circle would be completely missing, so there would not be a MouseArea to cover the one of the rectangles. Ideally, it would be that I have the rectangle with cutout circle seciton as its own shape, and the MouseArea only in that region

        1 Reply Last reply
        0
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by
          #4

          Use QQuickPaintedItem with QPainterPath, it can detect if it contains given point.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            maxwell31
            wrote on last edited by
            #5

            I solved it via using the QML Shape, e.g. like this:

            import QtQuick 2.0
            import QtQuick.Shapes 1.13
            
            
            Shape {
                id: root
                width: 500    height: 500
                property int radiusCenterOffset: 20    property int radius: 300
                property int inwards: calculated according to some criterion
                property color color: "black"
                signal clicked()
            
                containsMode: Shape.FillContains
                ShapePath {
                    strokeWidth: 1
                    strokeColor: root.color
                    fillColor: root.color
            
                    startX: 0; startY: 0
                    PathLine { x: root.inwards; y: 0 }
                    PathArc { x: root.width; y: root.height-root.inwards;radiusX: root.radius; radiusY: root.radius; direction: PathArc.Counterclockwise }
                    PathLine { x: root.width; y: root.height }
                    PathLine { x: 0; y: root.height }
                    PathLine { x: 0; y: 0 }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        if(root.contains(Qt.point(mouseX,mouseY)))
                            root.clicked()
                    }
                }
            }
            
            J.HilkJ 1 Reply Last reply
            3
            • IntruderExcluderI Offline
              IntruderExcluderI Offline
              IntruderExcluder
              wrote on last edited by
              #6

              Totally forgot about shapes. Nice solution!

              1 Reply Last reply
              0
              • M maxwell31

                I solved it via using the QML Shape, e.g. like this:

                import QtQuick 2.0
                import QtQuick.Shapes 1.13
                
                
                Shape {
                    id: root
                    width: 500    height: 500
                    property int radiusCenterOffset: 20    property int radius: 300
                    property int inwards: calculated according to some criterion
                    property color color: "black"
                    signal clicked()
                
                    containsMode: Shape.FillContains
                    ShapePath {
                        strokeWidth: 1
                        strokeColor: root.color
                        fillColor: root.color
                
                        startX: 0; startY: 0
                        PathLine { x: root.inwards; y: 0 }
                        PathArc { x: root.width; y: root.height-root.inwards;radiusX: root.radius; radiusY: root.radius; direction: PathArc.Counterclockwise }
                        PathLine { x: root.width; y: root.height }
                        PathLine { x: 0; y: root.height }
                        PathLine { x: 0; y: 0 }
                    }
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if(root.contains(Qt.point(mouseX,mouseY)))
                                root.clicked()
                        }
                    }
                }
                
                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @maxwell31 was about to suggest something similar 😉, but more power to you!

                Don't forget to use the topic tools to set this topic to solved. Thanks


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                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