Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to mapToGlobal a QRect?
Forum Updated to NodeBB v4.3 + New Features

How to mapToGlobal a QRect?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
15 Posts 4 Posters 7.3k 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.
  • M medyakovvit

    @Sriu1 said in How to mapToGlobal a QRect?:

    mouseMoveEvent

    is it parent's mouseMoveEvent?

    S Offline
    S Offline
    Sriu1
    wrote on last edited by
    #5

    @medyakovvit
    No its child's

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Can you show the complete code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Can you show the complete code ?

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

        @SGaist

        void ChildWidget::mouseMoveEvent(QMouseEvent* event)
        {

        if (event->buttons() & Qt::LeftButton)
        {
        QRect r=this->geometry();

           if(r.contains(event->globalPos()))//Also tried event->pos()
            {
                qDebug()<<"point inside";
            }
            else
            {
              qDebug()<<"point outside";
            }
        

        }

        QWidget::mouseMoveEvent(event);

        }

        If the child widget starts at 0,0 works fine...If child widget is not at origin "point outside" will be printed even if the pos is inside.Tried making point global.

        J.HilkJ 1 Reply Last reply
        0
        • S Sriu1

          @SGaist

          void ChildWidget::mouseMoveEvent(QMouseEvent* event)
          {

          if (event->buttons() & Qt::LeftButton)
          {
          QRect r=this->geometry();

             if(r.contains(event->globalPos()))//Also tried event->pos()
              {
                  qDebug()<<"point inside";
              }
              else
              {
                qDebug()<<"point outside";
              }
          

          }

          QWidget::mouseMoveEvent(event);

          }

          If the child widget starts at 0,0 works fine...If child widget is not at origin "point outside" will be printed even if the pos is inside.Tried making point global.

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

          @Sriu1 said in How to mapToGlobal a QRect?:

          If the child widget starts at 0,0 works fine...If child widget is not at origin "point outside" will be printed even if the pos is inside.Tried making point global.

          It's been a while since I used this, but mapToGlobal should work just fine!?

          > void ChildWidget::mouseMoveEvent(QMouseEvent* event)
           {
           
             if (event->buttons() & Qt::LeftButton)
             {
                  qDebug() << "Position relative to ChildWidget:" << objectName() << event->pos();
                  qDebug() << "Position relative to physical screen:" << objectName() << mapToGlobal(event->pos());
             }
          
           }
          

          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.

          S 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Sriu1 said in How to mapToGlobal a QRect?:

            If the child widget starts at 0,0 works fine...If child widget is not at origin "point outside" will be printed even if the pos is inside.Tried making point global.

            It's been a while since I used this, but mapToGlobal should work just fine!?

            > void ChildWidget::mouseMoveEvent(QMouseEvent* event)
             {
             
               if (event->buttons() & Qt::LeftButton)
               {
                    qDebug() << "Position relative to ChildWidget:" << objectName() << event->pos();
                    qDebug() << "Position relative to physical screen:" << objectName() << mapToGlobal(event->pos());
               }
            
             }
            
            S Offline
            S Offline
            Sriu1
            wrote on last edited by
            #9

            @J.Hilk Hi,
            event()->globalPos() and mapToGlobal(event->pos()) both give same.My problem was with rect.contains().how to map the rect of childWidget to global? So that even if event is occuring anywhere in the screen I should be able to know if its inside the qrect or outside

            J.HilkJ 1 Reply Last reply
            0
            • S Sriu1

              @J.Hilk Hi,
              event()->globalPos() and mapToGlobal(event->pos()) both give same.My problem was with rect.contains().how to map the rect of childWidget to global? So that even if event is occuring anywhere in the screen I should be able to know if its inside the qrect or outside

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

              @Sriu1 said in How to mapToGlobal a QRect?:

              @J.Hilk Hi,
              event()->globalPos() and mapToGlobal(event->pos()) both give same.My problem was with rect.contains().how to map the rect of childWidget to global? So that even if event is occuring anywhere in the screen I should be able to know if its inside the qrect or outside

              Well, the same way.

              QRect r=this->geometry();
              QRect globalRect(mapToGlobal( r.pos() ), r.size() );
              

              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.

              S 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @Sriu1 said in How to mapToGlobal a QRect?:

                @J.Hilk Hi,
                event()->globalPos() and mapToGlobal(event->pos()) both give same.My problem was with rect.contains().how to map the rect of childWidget to global? So that even if event is occuring anywhere in the screen I should be able to know if its inside the qrect or outside

                Well, the same way.

                QRect r=this->geometry();
                QRect globalRect(mapToGlobal( r.pos() ), r.size() );
                
                S Offline
                S Offline
                Sriu1
                wrote on last edited by Sriu1
                #11

                @J.Hilk Hi,
                I tried this
                QRect r=this->geometry();
                QPoint p(r.x(),r.y());
                QRect globalRect(mapToGlobal(p, r.size());

                getting error
                no matching function for call to ‘ChildWidget::mapToGlobal(QPoint&, QSize)’
                QRect globalRect(mapToGlobal(p, r.size());

                J.HilkJ 1 Reply Last reply
                0
                • S Sriu1

                  @J.Hilk Hi,
                  I tried this
                  QRect r=this->geometry();
                  QPoint p(r.x(),r.y());
                  QRect globalRect(mapToGlobal(p, r.size());

                  getting error
                  no matching function for call to ‘ChildWidget::mapToGlobal(QPoint&, QSize)’
                  QRect globalRect(mapToGlobal(p, r.size());

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

                  @Sriu1 there was a )missing in my example,


                  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.

                  S 1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @Sriu1 there was a )missing in my example,

                    S Offline
                    S Offline
                    Sriu1
                    wrote on last edited by Sriu1
                    #13

                    @J.Hilk
                    Still getting....
                    error: no matching function for call to ‘ChildWidget::mapToGlobal(QPoint&, QSize)’
                    QRect globalRect(mapToGlobal(p, r.size()));

                    QRect r=this->geometry();
                    QPoint p(r.x(),r.y());
                    QRect globalRect(mapToGlobal(p, r.size()));

                    if(!r.contains(event->globalPos()))

                    J.HilkJ 1 Reply Last reply
                    0
                    • S Sriu1

                      @J.Hilk
                      Still getting....
                      error: no matching function for call to ‘ChildWidget::mapToGlobal(QPoint&, QSize)’
                      QRect globalRect(mapToGlobal(p, r.size()));

                      QRect r=this->geometry();
                      QPoint p(r.x(),r.y());
                      QRect globalRect(mapToGlobal(p, r.size()));

                      if(!r.contains(event->globalPos()))

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

                      @Sriu1 again,
                      look at the parenthesis, mapToGlobal expects 1 argument, a Qpoint, and returns the maped point, you try to pass it a Qpoint and QSize!


                      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
                      • S Offline
                        S Offline
                        Sriu1
                        wrote on last edited by
                        #15

                        @J-Hilk
                        Compiled.. But still I'm getting "point outside" event if its inside.

                        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