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. Is there is existing function to find midpoint of QLineF
Forum Updated to NodeBB v4.3 + New Features

Is there is existing function to find midpoint of QLineF

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.7k Views 2 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I went through http://doc.qt.io/qt-4.8/qlinef-members.html and its list of functions . I could not find a readymade function that finds the midpoint of the QLineF .Is the any existing function to find the same . If point

    How about

    QPointF mid = QPointF((QLineF.p1().x()+ QLineF.p2().x())/2) ,(QLineF.p1().y()+ QLineF.p2().y())/2 )

    Please let me know

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Nothing exist in qt. you can apply mathematical formula and get it.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • K Offline
        K Offline
        kenchan
        wrote on last edited by
        #3

        I think you want the center() function?

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          I cannot find anyone

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kenchan
            wrote on last edited by kenchan
            #5

            Ah sorry, I see you are using an older version than me (Qt 5.8). It probably does not exist in Qt 4.8. So it is the manual method for you :-).
            from the QT 5.8 docs. it does this 0.5 * p1() + 0.5 * p2() which is the equivalent of yours.

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yonnak
              wrote on last edited by
              #6

              I haven't test it but you can try something like this:
              QRectF(line.P1(),line.p2()).center()

              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