Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. mousePressEvent is based on the geometry ? how can i make the geometry be a triangle ?

mousePressEvent is based on the geometry ? how can i make the geometry be a triangle ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.0k 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.
  • O Offline
    O Offline
    opengpu
    wrote on last edited by opengpu
    #1

    mousePressEvent is based on the geometry? how can i make the geometry be a triangle?
    because i draw a triangle in paintEvent. and i setFixedSize by the triangle's width and height.
    however i found while i deal with 2 overlapped QWidget(triangle) mouseEvent, it's wrong.
    eg. presisely i clicked on the lower triangle's some area point, however that point is belong to the upper triangle's rect, so the mouseEvent is taken by the upper one...but actually i want the lower one respond that click.

    J.HilkJ sierdzioS 2 Replies Last reply
    0
    • O opengpu

      mousePressEvent is based on the geometry? how can i make the geometry be a triangle?
      because i draw a triangle in paintEvent. and i setFixedSize by the triangle's width and height.
      however i found while i deal with 2 overlapped QWidget(triangle) mouseEvent, it's wrong.
      eg. presisely i clicked on the lower triangle's some area point, however that point is belong to the upper triangle's rect, so the mouseEvent is taken by the upper one...but actually i want the lower one respond that click.

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

      @opengpu I don't think you actually can change it from a rectangle into anything else.

      However you could store you triangle shape inside a QPolygon and check the point during the mousePress event via QPolygon::containsPoint if it's inside the shape or not.


      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
      1
      • O opengpu

        mousePressEvent is based on the geometry? how can i make the geometry be a triangle?
        because i draw a triangle in paintEvent. and i setFixedSize by the triangle's width and height.
        however i found while i deal with 2 overlapped QWidget(triangle) mouseEvent, it's wrong.
        eg. presisely i clicked on the lower triangle's some area point, however that point is belong to the upper triangle's rect, so the mouseEvent is taken by the upper one...but actually i want the lower one respond that click.

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        @opengpu said in mousePressEvent is based on the geometry? how can i make the geometry be a triangle?:

        how can i make the geometry be a triangle?

        You can't. Bounding rect is always a rectangle. What you can do is to check if there is something painted under the mouse cursor in the top-level triangle, and if not ignore the event (set accepted to false) - then it will be sent to next triangle below it.

        (Z(:^

        1 Reply Last reply
        1
        • O Offline
          O Offline
          opengpu
          wrote on last edited by
          #4

          i now solved the visual problem by using raise() or lower().
          and the mouseEvent is not going down directly to the lower one.
          i am sorry, but i don't quite understand ur method, how can i "ignore the event (set accepted to false)" in mousePressEvent?

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5
            void mousePressEvent(QMouseEvent *event) {
              if (mouse is not above triangle shape)
                event->setAccepted(false);
            }
            

            (Z(:^

            O 1 Reply Last reply
            3
            • O Offline
              O Offline
              opengpu
              wrote on last edited by
              #6

              i tried, but not work, the lower one doesnot revieve the event.

              class Triangle
              {
                  void mousePressEven(QMouseEvent* e)
                  {
                      if (m_polygon.containsPoint(mapFromGlobal(e->globalPos()), Qt::OddEvenFill))
                      {
                           m_pressed = true;
                           m_lastPos = e->globalPos();
                           raise();
                      }
                      else
                      {
                          lower();
                          e->setAccepted(false);
                          //return QWidget::mousePreddEvent(e); //whether do this or not, both not work.
                       }
                  }
              }
              
              1 Reply Last reply
              0
              • O Offline
                O Offline
                opengpu
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • sierdzioS sierdzio
                  void mousePressEvent(QMouseEvent *event) {
                    if (mouse is not above triangle shape)
                      event->setAccepted(false);
                  }
                  
                  O Offline
                  O Offline
                  opengpu
                  wrote on last edited by
                  #8

                  @sierdzio hello?
                  anyone help?

                  sierdzioS 1 Reply Last reply
                  0
                  • O opengpu

                    @sierdzio hello?
                    anyone help?

                    sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    @opengpu said in mousePressEvent is based on the geometry ? how can i make the geometry be a triangle ?:

                    @sierdzio hello?
                    anyone help?

                    I don't have more ideas. If I had, I would have replied.

                    (Z(:^

                    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