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 a way to get the horizonal advance of every character in a string?

Is there a way to get the horizonal advance of every character in a string?

Scheduled Pinned Locked Moved Solved General and Desktop
font size
6 Posts 3 Posters 402 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.
  • G Offline
    G Offline
    GeraldBrandt
    wrote on 22 Mar 2020, 16:25 last edited by
    #1

    Hi,

    I'm looking for something like GetPartialTextExtents() in wxWidgets or GDI+ MeasureCharacterRanges(). Does QT have something like that? QFontMetrics doesn't seem to.

    Gerald

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 22 Mar 2020, 16:29 last edited by
      #2

      What's wrong with QFontMetrics::horizontalAdvance(QChar ch) ?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      G 1 Reply Last reply 24 Mar 2020, 14:51
      2
      • C Christian Ehrlicher
        22 Mar 2020, 16:29

        What's wrong with QFontMetrics::horizontalAdvance(QChar ch) ?

        G Offline
        G Offline
        GeraldBrandt
        wrote on 24 Mar 2020, 14:51 last edited by
        #3

        @Christian-Ehrlicher Nothing, except that I'm calling it over 600,000 times.

        When I switched from individual character measuring to string measuring (getting each characters width) in wxWidgets, I got a 10x speed improvement.

        Gerald

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 24 Mar 2020, 14:59 last edited by
          #4

          @GeraldBrandt said in Is there a way to get the horizonal advance of every character in a string?:

          Nothing, except that I'm calling it over 600,000 times.

          If you really need it then add a cache.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 24 Mar 2020, 15:04 last edited by mrjj
            #5

            Hi
            Just as a note
            There is an overload that takes a QString

            int horizontalAdvance(const QString &, int len = -1) const;

            However, if that is faster then looping the string your self and call the QChar version i don't know.

            G 1 Reply Last reply 24 Mar 2020, 15:43
            0
            • M mrjj
              24 Mar 2020, 15:04

              Hi
              Just as a note
              There is an overload that takes a QString

              int horizontalAdvance(const QString &, int len = -1) const;

              However, if that is faster then looping the string your self and call the QChar version i don't know.

              G Offline
              G Offline
              GeraldBrandt
              wrote on 24 Mar 2020, 15:43 last edited by
              #6

              Actually, 100% my fault. Things are plenty fast. I had an extra call to size() in my method that I didn't need, and that is a slow call.

              Thanks,
              Gerald

              1 Reply Last reply
              2

              6/6

              24 Mar 2020, 15:43

              • Login

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