Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Aug 2011

    MouseArea for QDeclarativeItem subclass

    i have a custom type, QDeclarativeItem subclass called polygon.
    I override shape, boundingRect and paint functions in it.
    I can see the polygons that i describe in the below QML code:

    import MyTypes 1.0
    import QtQuick 1.0
    import Qt 4.7
    Item {
        id: container
        width: 350; height: 250
         Polygon {
             id: aPolygon
             width: 20; height: 20
             name: "A simple polygon"
             color: "blue"
             Point{x:20.0; y:40.0},
             Point{x:40.0; y:40.0},
             Point{x:40.0; y:20.0},
             Point{x:20.0; y:20.0}
                 anchors.fill: parent
                 drag.target: aPolygon
                 drag.axis: Drag.XandYAxis
                 drag.minimumX: 0
                 drag.maximumX: container.width - parent.width
                 drag.minimumY: 0
                 drag.maximumY: container.height - parent.width
                 onPressed:console.log("==============   ==onPressed")
         Polygon {
             id: bPolygon
             width: 20; height: 20
             name: "A simple polygon"
             color: "blue"
             Point{x:60.0; y:80.0},
             Point{x:80.0; y:80.0},
             Point{x:80.0; y:60.0},
             Point{x:60.0; y:60.0}
                 //hoverEnabled: false
                 enabled: visible
                 hoverEnabled: visible
                 anchors.fill: parent
                 acceptedButtons: Qt.LeftButton | Qt.RightButton
                 onEntered: {
                     console.log("==============   ==onEntered")

    The problem is that MouseArea cares the x, y, width and height properties of my polygon items, not the shape of my polygons.

    For example for first polygon onPressed work for the rectangle x:0;y:0;width:20;height:20

    How can i make MouseArea work for the polygon that vertices define.

    I have overrided shape function, what should i do else?


  2. #2
    Super Contributor
    Join Date
    Mar 2009

    Re: MouseArea for QDeclarativeItem subclass

    I think you can give some "borders" to your "squared" MouseArea in this way:
    Since poligon area is smaller than the MouseArea area, you can use in OnPressed slot you use Item::mapToItem to check if the click happened on the poligon or not,
    So, if you click outside the poligon, mouseArea::mapToItem(pos, poligonObj) will return an invalid position value.
    This trick could permit you can to discard these events and process only the valid ones.

Similar Threads

  1. QListWidgetItem subclass
    By pigling in forum Qt
    Replies: 11
    Last Post: 2011-05-05, 12:32
  2. How to disable mousearea in condition?
    By VVNart in forum [Archived] Qt Quick
    Replies: 2
    Last Post: 2011-05-05, 10:56
  3. calling of subclass destructor
    By ojve in forum Symbian
    Replies: 2
    Last Post: 2010-03-23, 15:07
  4. handling commands from subclass
    By stoun in forum Mobile Java General
    Replies: 1
    Last Post: 2003-04-20, 14:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts