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. Non Rectangular Mouse Area. (Triangular or polygon) [Solved]

Non Rectangular Mouse Area. (Triangular or polygon) [Solved]

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 4.5k 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.
  • D Offline
    D Offline
    dasun
    wrote on last edited by
    #1

    Is there a way to catch mouse event in a triangular or polygon area? At least a workaround. I'm using Qt Quick 2

    1 Reply Last reply
    1
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      You can write a custom QQuickItem in C++. There is an example called maskedmousearea included in Qt 5.1 which should demonstrate how to do this.

      It is also possible to do this in pure QML by handling onPressed and onReleased manually and simply verifying if the mouse area is within your region.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dasun
        wrote on last edited by
        #3

        Thank you! by the time you reply this I figured it out, and now I'm writing a custom QQuickItem.

        I have another issue related to this, seems mousePressEvent(or any other mouse events) not triggered.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jens
          wrote on last edited by
          #4

          You should just look at maskedmousearea as it does exactly what you want. Perhaps you forgot to do the following:

          @
          setAcceptHoverEvents(true);
          setAcceptedMouseButtons(Qt::LeftButton);
          @

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dasun
            wrote on last edited by
            #5

            Wonderful, it works!
            Thank you, very much.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Larpon
              wrote on last edited by Larpon
              #6

              Necro asking :)

              Is this still the way to go in 2016?
              It's seems like the example has vanished in Qt5.5 (probably earlier versions)

              T 1 Reply Last reply
              0
              • L Larpon

                Necro asking :)

                Is this still the way to go in 2016?
                It's seems like the example has vanished in Qt5.5 (probably earlier versions)

                T Offline
                T Offline
                TOMATO_QT
                wrote on last edited by TOMATO_QT
                #7

                @Larpon

                I found the maskmousearea example in the Qt 5.5 install at /Examples/Qt-5.5/quick/customItems/

                1 Reply Last reply
                1
                • L Offline
                  L Offline
                  Larpon
                  wrote on last edited by
                  #8

                  @TOMATO_QT
                  Thanks!

                  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