Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Multiple QRect

    General and Desktop
    qrect mouseevent eventfilter
    2
    9
    3300
    Loading More Posts
    • 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.
    • S
      Sidii last edited by

      Hi All,
      I have added an event filter for Mouse Clicks. I am checking whether the mouse click is inside a QRect or not. If it is inside QRect, it is OK else block the event.This approach is OK for one QRect or two QRect.

      Now the problem is that i do not know in advance how many QRects are present as this info get at runtime. I basically want to have OR condition between all the QRects like this:

      ' if(QRect(x1,y1,w1,h1).contains(e->pos()) || QRect(x2,y2,w2,h2).contains(e->pos()) || QRect(x3,y3,w3,h3).contains(e->pos()) || QRect(x4,y4,w4,h4).contains(e->pos()) || QRect(x5,y5,w5,h5).contains(e->pos())) '

      But as i do not know before hand how many QRects will come, i am not able to write the above statement. I want to know if there is any operation on QRect that i can perform to get the union of all the QRects so that i can have one final QRect at the end and i can put that inside the if condition. Kindly give some pointers how to proceed??

      Thanks
      Sid

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @Sidii last edited by

        @Sidii You can keep a QList of QRect (i.e when QRect come add it to QList) and when the event of interest is triggered check throughout the list. In this way you need not require the hardcoded OR condition.

        157

        S 1 Reply Last reply Reply Quote 1
        • S
          Sidii @p3c0 last edited by

          @p3c0 Thanks for your reply. But i have one question. How will i put OR condition between all the elements of QList?
          Example:
          if(list.at(0).contains(e.pos())|| list.at(1).contains(e.pos()) || list.at(2).contains(e.pos()))

          As i do not know in advance how many QList elements i have to put inside the if condition.

          Kindly give some hints.

          Thanks

          p3c0 2 Replies Last reply Reply Quote 0
          • p3c0
            p3c0 Moderators @Sidii last edited by

            @Sidii No need of OR condition. Just iterate over the list. For eg:

            QRect r1(0,0,30,60);
            QRect r2(10,20,40,60);
            QRect r3(20,30,50,60);
            
            QList<QRect> list;
            list.append(r1);
            list.append(r2);
            list.append(r3);
            
            foreach(QRect rect, list) {
                if(rect.contains(e.pos())) {
                    qDebug() << rect;
                }
            }
            

            157

            1 Reply Last reply Reply Quote 1
            • p3c0
              p3c0 Moderators @Sidii last edited by

              @Sidii Make sure when a new QRect comes, add it to the QList.

              157

              S 2 Replies Last reply Reply Quote 0
              • S
                Sidii @p3c0 last edited by

                @p3c0 Thanks i got it :)

                1 Reply Last reply Reply Quote 0
                • S
                  Sidii @p3c0 last edited by

                  @p3c0 Will mark this thread as solved !!

                  p3c0 1 Reply Last reply Reply Quote 0
                  • p3c0
                    p3c0 Moderators @Sidii last edited by

                    @Sidii Ok. You're Welcome :)

                    157

                    p3c0 1 Reply Last reply Reply Quote 0
                    • p3c0
                      p3c0 Moderators @p3c0 last edited by

                      @p3c0 You can upvote answer if you find it useful ;)

                      157

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post