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. Label Text with two different alignments
Forum Updated to NodeBB v4.3 + New Features

Label Text with two different alignments

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 260 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.
  • I Offline
    I Offline
    Infestor
    wrote on 20 Feb 2021, 20:00 last edited by
    #1

    HI,

    im currently struggling with a simple issue that i cant get solved. What i want to do is to list some items and their numerical value vertically in QLabels e.g.
    x: 5
    y_foo: 10
    bar_x: 77.1

    However i would like to achieve that the text are aligned on the left and the numbers are aligned on the right. Is there a way to do this?
    I tried using Layouts, but i have problems understanding how the different spacing methods all work.

    J 1 Reply Last reply 20 Feb 2021, 20:02
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 20 Feb 2021, 20:02 last edited by
      #2

      Hi,

      I would go with a QFormLayout. It looks like what you are trying to get to.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply 20 Feb 2021, 20:06
      1
      • I Infestor
        20 Feb 2021, 20:00

        HI,

        im currently struggling with a simple issue that i cant get solved. What i want to do is to list some items and their numerical value vertically in QLabels e.g.
        x: 5
        y_foo: 10
        bar_x: 77.1

        However i would like to achieve that the text are aligned on the left and the numbers are aligned on the right. Is there a way to do this?
        I tried using Layouts, but i have problems understanding how the different spacing methods all work.

        J Offline
        J Offline
        JonB
        wrote on 20 Feb 2021, 20:02 last edited by
        #3

        @Infestor
        You could use a QGridLayout with two columns. You shouldn't need any "spacing methods" then.

        1 Reply Last reply
        1
        • S SGaist
          20 Feb 2021, 20:02

          Hi,

          I would go with a QFormLayout. It looks like what you are trying to get to.

          J Offline
          J Offline
          JonB
          wrote on 20 Feb 2021, 20:06 last edited by JonB
          #4

          @SGaist
          The trouble with QFormLayout is that it has inbuilt alignments according to overall style, being set for different windowing systems/styles. The OP specifies left alignment for the left-hand labels; but if you look at https://doc.qt.io/qt-5/qformlayout.html#details some styles align these right. That's why I suggested QGridLayout.

          Oh, I see there is QFormLayout::setLabelAlignment() to alter that. Well, up to the OP. Note that QFormLayout is strictly intended for only two columns, QGridLayout you can have however many you want.

          1 Reply Last reply
          0

          3/4

          20 Feb 2021, 20:02

          • Login

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