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. QLabel, how to anchor and align right ?
Qt 6.11 is out! See what's new in the release blog

QLabel, how to anchor and align right ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 3.5k Views 2 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.
  • JonBJ JonB

    @SPlatten Don't you do that in the layout(s) you put them in?

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #3

    @JonB , I'm building the layout with widgets at runtime, the specification is supplied in an XML file.

    Kind Regards,
    Sy

    JonBJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @JonB , I'm building the layout with widgets at runtime, the specification is supplied in an XML file.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #4

      @SPlatten
      Yes but that has nothing to do with it. Have you looked at e.g. void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()), the alignment argument? I'm only guessing.

      SPlattenS 2 Replies Last reply
      2
      • JonBJ JonB

        @SPlatten
        Yes but that has nothing to do with it. Have you looked at e.g. void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()), the alignment argument? I'm only guessing.

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #5

        @JonB , thank you, I will try it out..

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • JonBJ JonB

          @SPlatten
          Yes but that has nothing to do with it. Have you looked at e.g. void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()), the alignment argument? I'm only guessing.

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #6

          @JonB , what I'm actually looking for I don't think exists in Qt. It seems that QLabels are positioned using the bottom left coordinate then alignment is applied which uses the geometry of the QLabel to adjust the text according to the width and x coordinate.

          What I actually wanted to do is regardless of the width in the geometry I wanted to position the QLabel by the Anchor position, so if I set the anchor to bottom right and the alignment to right then any text would be displayed right of the anchor position and could never move past this position.

          Kind Regards,
          Sy

          JonBJ 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @JonB , what I'm actually looking for I don't think exists in Qt. It seems that QLabels are positioned using the bottom left coordinate then alignment is applied which uses the geometry of the QLabel to adjust the text according to the width and x coordinate.

            What I actually wanted to do is regardless of the width in the geometry I wanted to position the QLabel by the Anchor position, so if I set the anchor to bottom right and the alignment to right then any text would be displayed right of the anchor position and could never move past this position.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #7

            @SPlatten
            No idea since QLabel does not have any Anchor property.

            so if I set the anchor to bottom right and the alignment to right then any text would be displayed right of the anchor position and could never move past this position.

            If the anchor is bottom right then how can any text be displayed to the right of that?

            I don't understand, so best of luck.

            SPlattenS 1 Reply Last reply
            0
            • JonBJ JonB

              @SPlatten
              No idea since QLabel does not have any Anchor property.

              so if I set the anchor to bottom right and the alignment to right then any text would be displayed right of the anchor position and could never move past this position.

              If the anchor is bottom right then how can any text be displayed to the right of that?

              I don't understand, so best of luck.

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #8

              @JonB , What I mean is that when the alignment is set to right and the anchor is specified as right that any text is always written to the same X,Y position but instead of it being displayed where each letter advances from X, that the draw function knows the anchor and the alignment is right so it adjusts the start position to allow for the left most character to be displayed where the final character right most position does not go past the initial X,Y position.

              Kind Regards,
              Sy

              JonBJ 1 Reply Last reply
              0
              • SPlattenS SPlatten

                @JonB , What I mean is that when the alignment is set to right and the anchor is specified as right that any text is always written to the same X,Y position but instead of it being displayed where each letter advances from X, that the draw function knows the anchor and the alignment is right so it adjusts the start position to allow for the left most character to be displayed where the final character right most position does not go past the initial X,Y position.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #9

                @SPlatten
                Sounds to me like align right but with a right margin.

                SPlattenS 1 Reply Last reply
                2
                • JonBJ JonB

                  @SPlatten
                  Sounds to me like align right but with a right margin.

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #10

                  @JonB , please explain.

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    Hi
                    Im not sure either, I understand the alignment you are after.

                    When I read it, I see like this for me

                    alt text

                    SPlattenS 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      Hi
                      Im not sure either, I understand the alignment you are after.

                      When I read it, I see like this for me

                      alt text

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #12

                      @mrjj , that looks like exactly what I am after.

                      Kind Regards,
                      Sy

                      mrjjM 1 Reply Last reply
                      0
                      • SPlattenS SPlatten

                        @mrjj , that looks like exactly what I am after.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        @SPlatten
                        Oh :)
                        Well its a GridLayout
                        Then all Labels have
                        alt text

                        The Gridlayout has
                        alt text

                        SPlattenS JonBJ 2 Replies Last reply
                        1
                        • mrjjM mrjj

                          @SPlatten
                          Oh :)
                          Well its a GridLayout
                          Then all Labels have
                          alt text

                          The Gridlayout has
                          alt text

                          SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by
                          #14

                          @mrjj , actually I think I can do exactly what I want with just the layout and without a margin.

                          Kind Regards,
                          Sy

                          1 Reply Last reply
                          1
                          • mrjjM mrjj

                            @SPlatten
                            Oh :)
                            Well its a GridLayout
                            Then all Labels have
                            alt text

                            The Gridlayout has
                            alt text

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #15

                            @mrjj So align right with a right margin :)

                            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