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. Number of characters that fit into given width
QtWS25 Last Chance

Number of characters that fit into given width

Scheduled Pinned Locked Moved Unsolved General and Desktop
qfontmetricsqstring
4 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    Arthur Araruna
    wrote on 1 Oct 2018, 16:01 last edited by
    #1

    I would like to be able to determine, given a string (QString) that is supposed to be displayed within a given width (qreal) area, how many of its characters would fit without overflowing that width.

    Is there any helper class / function that I can use to get this information, or do I need to create my own? If I do, what measurements should I include in this calculation? I have access to the QFont and QFontMetrics objects that will be used.

    Thank you.

    1 Reply Last reply
    0
  • V Offline
    V Offline
    VRonin
    wrote on 1 Oct 2018, 16:35 last edited by VRonin 10 Jan 2018, 16:35
    #2

    Something like http://doc.qt.io/qt-5/qfontmetrics.html#elidedText ?

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    A 1 Reply Last reply 1 Oct 2018, 19:20
    1
  • A Offline
    A Offline
    Arthur Araruna
    wrote on 1 Oct 2018, 18:47 last edited by Arthur Araruna 10 Jan 2018, 18:51
    #3

    Maybe yes. Most likely to work.

    The problem would be if ::ElideNone does not work as expected... Also, it would be better if I didn't have to make another QString in order to get just the number of characters.

    But I'll give it a go.

    Thank you.

    1 Reply Last reply
    0
  • A Offline
    A Offline
    Arthur Araruna
    replied to VRonin on 1 Oct 2018, 19:20 last edited by Arthur Araruna 10 Mar 2018, 19:07
    #4

    @VRonin said in Number of characters that fit into given width:

    Something like http://doc.qt.io/qt-5/qfontmetrics.html#elidedText ?

    Turns out it will not work for me.

    The QString returned includes the ellipsis and there is no way to avoid them, because passing Qt::ElideNone means "do not truncate" instead of "omit the ellipsis" (as I feared).

    1 Reply Last reply
    0

1/4

1 Oct 2018, 16:01

topic:navigator.unread, 3
  • Login

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