Results 1 to 1 of 1

Thread: How to design a solution for QLabel text alignment?

  1. #1
    Join Date
    Sep 2020
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How to design a solution for QLabel text alignment?

    Hi Everyone,

    QT newbie here.

    Just wondering if there is a way of designing a solution using QT for this requirement.

    I have two labels.
    label1
    label2

    Font: Arial (non monospace font)

    $ amounts are variable in nature.
    The label should be displayed in such a way that it appears like the . are aligned as per the below pics

    Sample1
    sample1.png

    I tried adding the QLabels (label1 and label2) to QVBoxLayout. But it didn't help.

    I noticed that input to be right-justified has a range:

    //$X.XX e.g. $5.00
    //$XX.XX e.g. $50.00
    //$XX.XX e.g. $500.00
    //$XX.XX e.g. $4999.00 (Max)

    If my QString value2 contains the above strings, I count the characters e.g.
    5
    6
    7
    8 (Max)

    Then I take the value1 let us say $2.36 which will always be 5 chars and do:

    Qt Code:
    1. value1 = value1.rightJustified(lengthOfValue2String,QLatin1Char(' '), true);
    To copy to clipboard, switch view to plain text mode 

    The problem obviously is non-monospaced Arial font which I cannot change unfortunately.

    But I noticed that if I do QLatin1Char('$') instead of space, both values are aligned as per the images in my original post. But with $ instead of space which I don't want.

    Is there a way of using the fillChar with $ and then make them invisible? : )

    Any advice will be appreciated.

    Thanks.
    Attached Images Attached Images

Similar Threads

  1. Replies: 1
    Last Post: 11th March 2014, 11:20
  2. geting QLabel text ontop of other QLabel displaying image
    By krystosan in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2013, 17:35
  3. Replies: 0
    Last Post: 24th October 2011, 12:52
  4. Replies: 10
    Last Post: 9th June 2010, 14:12
  5. Solution for render text in some low-level class
    By deedw in forum Qt Programming
    Replies: 0
    Last Post: 19th April 2010, 12:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.