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. Multiple QRect
Forum Update on Monday, May 27th 2025

Multiple QRect

Scheduled Pinned Locked Moved General and Desktop
qrectmouseeventeventfilter
9 Posts 2 Posters 4.1k 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.
  • S Offline
    S Offline
    Sidii
    wrote on 31 Mar 2015, 03:44 last edited by
    #1

    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

    P 1 Reply Last reply 31 Mar 2015, 05:18
    0
    • S Sidii
      31 Mar 2015, 03:44

      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

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 31 Mar 2015, 05:18 last edited by
      #2

      @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 31 Mar 2015, 06:01
      1
      • P p3c0
        31 Mar 2015, 05:18

        @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.

        S Offline
        S Offline
        Sidii
        wrote on 31 Mar 2015, 06:01 last edited by
        #3

        @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

        P 2 Replies Last reply 31 Mar 2015, 06:09
        0
        • S Sidii
          31 Mar 2015, 06:01

          @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

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 31 Mar 2015, 06:09 last edited by
          #4

          @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
          1
          • S Sidii
            31 Mar 2015, 06:01

            @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

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 31 Mar 2015, 06:10 last edited by
            #5

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

            157

            S 2 Replies Last reply 31 Mar 2015, 06:35
            0
            • P p3c0
              31 Mar 2015, 06:10

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

              S Offline
              S Offline
              Sidii
              wrote on 31 Mar 2015, 06:35 last edited by
              #6

              @p3c0 Thanks i got it :)

              1 Reply Last reply
              0
              • P p3c0
                31 Mar 2015, 06:10

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

                S Offline
                S Offline
                Sidii
                wrote on 31 Mar 2015, 06:36 last edited by
                #7

                @p3c0 Will mark this thread as solved !!

                P 1 Reply Last reply 31 Mar 2015, 06:37
                0
                • S Sidii
                  31 Mar 2015, 06:36

                  @p3c0 Will mark this thread as solved !!

                  P Offline
                  P Offline
                  p3c0
                  Moderators
                  wrote on 31 Mar 2015, 06:37 last edited by
                  #8

                  @Sidii Ok. You're Welcome :)

                  157

                  P 1 Reply Last reply 31 Mar 2015, 06:39
                  0
                  • P p3c0
                    31 Mar 2015, 06:37

                    @Sidii Ok. You're Welcome :)

                    P Offline
                    P Offline
                    p3c0
                    Moderators
                    wrote on 31 Mar 2015, 06:39 last edited by
                    #9

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

                    157

                    1 Reply Last reply
                    0

                    2/9

                    31 Mar 2015, 05:18

                    topic:navigator.unread, 7
                    • Login

                    • Login or register to search.
                    2 out of 9
                    • First post
                      2/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved