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. How to use qml to implement a navigation pad?
Forum Updated to NodeBB v4.3 + New Features

How to use qml to implement a navigation pad?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 2.6k 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.
  • N Offline
    N Offline
    nan3113
    wrote on last edited by
    #1

    the navigation pad have five buttons:left, right,up,down,select. select button in center, other four buttons surround select button. looks like the picture in this address:http://jerk66.blog.163.com/album/#m=2&aid=240084932&pid=7707752037

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

      I use QML and extension plugin to achieve the polygon navigation.

      Using QML to display the image changing effect, and use c++ extension plugin inherited from "QDeclarativeItem":http://qt-project.org/doc/qt-4.8/qdeclarativeitem.html to import each parts of region of images to verify which part I navigate on.

      Try to store those images , and use mousePressEvent, mouseReleaseEvent, hoverMoveEvent virtual function from "QGraphicsItem":http://qt-project.org/doc/qt-4.8/qgraphicsitem.html to catch mouse event. Then using the the QPointF of event::pos() and put into the "QImage::pixel()":http://qt-project.org/doc/qt-4.8/qimage.html#pixel to verify whether part of image it right on that. (Use "qAlpha()":http://qt-project.org/doc/qt-4.8/qcolor.html#qAlpha to verify it) (The image size should be the same with total panel, and the part of image's has alpha value, the rest of that is 0)

      If match is occurs, then signal the identify of part image to QML. The QML try to display its correspondent effective image.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nan3113
        wrote on last edited by
        #3

        Thanks for jacky's answer, but I'm not clear about what you said, Can you give me an example code about this?

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nan3113
          wrote on last edited by
          #4

          If I just want to use qml and image to implement it, How can I judge which region is clicked?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bomb3rman
            wrote on last edited by
            #5

            Well, I guess it wont work with just QML. You have to write your own extension Plugin in C++ if you want to be able to determine if the exact shape of a button is selected. A MouseArea in QML does unfortunately only support a rectangular region.
            I would however just place 4 rectangular MouseAreas over it, the result will not be perfect but I think it will be good enough for most use cases.

            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