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. Dynamic text sizing and alignment based on screen resolution
Forum Updated to NodeBB v4.3 + New Features

Dynamic text sizing and alignment based on screen resolution

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.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.
  • J Offline
    J Offline
    jimbo2
    wrote on last edited by
    #1

    Hi everyone, I'm having an issue with how to display text that I hope you may be able to help with.

    I'm trying to display a title menu for a game, with six entries. Each would be a text string backed by a semi transparant backing and offset to the side of the screen to allow the artwork to show through. I am using the graphics view framework but manually drawing everything within the scene object myself because I want more depth layers than the framework offers.

    I want to minimise how much space these entries take up while still making them human readable, so ideally I would like to do the following:

    1. Calculate 10% of the screen height and select an appropriate font matching this size, vertical alignment is handled using this as a step value.
    2. Calculate how wide the text entries will be utilising this font and then use the appropriate horizontal alignment based on this value.
    3. Render the text to the screen.

    The second half of part (1) and part (2) have me really stumped at the moment. This is initially targetting Symbian but will be ported to desktop afterwards.

    Thank you kindly for any help.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RazrFalcon
      wrote on last edited by
      #2
      1. maybe something like this:
        @ QFont font("Arial");
        font.setPointSize(14);
        QFontMetrics fm(font);
        qDebug()<<fm.width("1234")<<"pix";@

      out:
      44 pix

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jimbo2
        wrote on last edited by
        #3

        That's fantastic, thank you! I had completely missed the QFontMetrics class.

        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