Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved QLabel position is not centered

    General and Desktop
    3
    8
    2103
    Loading More Posts
    • 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.
    • R
      ranshalit last edited by ranshalit

      Hello,

      I try to position qlabel (which holds an image) in point (x,y).
      I want to the senter of the image will be in (x,y)
      but when I position qlabel with:
      label->move(x,y)
      I see that the left & up corner of the image is positioned in (x,y).
      How can make it position the center of the label in (x,y) ?
      Thanks for any advise.
      Ran

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Just do the math when dealing with that kind of stuff. You know the size of the label so if you'd like to move the centre, update the coordinates while taking into account the size of the label.

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

        R 1 Reply Last reply Reply Quote 1
        • R
          ranshalit last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • R
            ranshalit @SGaist last edited by

            @SGaist
            Hi,

            Thanks, that's solved it.
            Yet, I would like to ask one more thing please: on attaching an image to QLable, it seems that the size of qlabel is not the same size as the image, i.e. I need to setMinimumWidth/Height of the QLable, so seems that I am forced to use the knowledge of image size anyway inside code, Right ?

            Thanks

            J.Hilk 1 Reply Last reply Reply Quote 0
            • J.Hilk
              J.Hilk Moderators @ranshalit last edited by

              @ranshalit hi, if the QLabel is not restricted in its size than it should scale itself to the Pixmap that you asgin.

              If you set the scaledContents property of the QLabel to true, it it will adjust the Pixmap to fit the QLabels current form, but it will ignore the aspect ratio.

              You can also asign the Pixmap scaled.
              label->setPixmap(p.scaled(label->size(), Qt::KeepAspectRatio);

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

              Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply Reply Quote 1
              • R
                ranshalit last edited by

                Not sure why but its contents is (6,16) although the image is (20,20).
                It has scaled contents (I've set with setScaledContents(true) and verified with hasScaledContents().
                Note that I am not using Pixmap, but setStyleSheet("Qlabel { image: url(: /resource/img.png); }");

                J.Hilk 1 Reply Last reply Reply Quote 0
                • J.Hilk
                  J.Hilk Moderators @ranshalit last edited by J.Hilk

                  @ranshalit If you use QStyleSheet than its a whole different matter.
                  setScaledContents actually has no effect, you don't need that line and The QLabel does not adjust its size to the image.

                  You'll have to call QLabel::resize() manualy.

                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  R 1 Reply Last reply Reply Quote 1
                  • R
                    ranshalit @J.Hilk last edited by

                    @J.Hilk
                    Ok, Thanks a lot !

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post