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
QtWS25 Last Chance

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

    p3c0P 1 Reply Last reply
    0
    • S Sidii

      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

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on 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
      1
      • p3c0P p3c0

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

        p3c0P 2 Replies Last reply
        0
        • S Sidii

          @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

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on 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

            @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

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

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

            157

            S 2 Replies Last reply
            0
            • p3c0P p3c0

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

              S Offline
              S Offline
              Sidii
              wrote on last edited by
              #6

              @p3c0 Thanks i got it :)

              1 Reply Last reply
              0
              • p3c0P p3c0

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

                S Offline
                S Offline
                Sidii
                wrote on last edited by
                #7

                @p3c0 Will mark this thread as solved !!

                p3c0P 1 Reply Last reply
                0
                • S Sidii

                  @p3c0 Will mark this thread as solved !!

                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @Sidii Ok. You're Welcome :)

                  157

                  p3c0P 1 Reply Last reply
                  0
                  • p3c0P p3c0

                    @Sidii Ok. You're Welcome :)

                    p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #9

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

                    157

                    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