Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Label help

Label help

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 3 Posters 510 Views
  • 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.
  • N Offline
    N Offline
    nick_d12
    wrote on last edited by
    #1

    c352aeb0-023f-4bce-8881-03ca83080582-image.png

    so i have a label with a gray background as a visualizer I want to make the label height the same size as the text so I want to bring the gray or the label size down to the point where the gray is just surrounding the time Any ideas?

    jsulmJ 1 Reply Last reply
    0
    • N nick_d12

      c352aeb0-023f-4bce-8881-03ca83080582-image.png

      so i have a label with a gray background as a visualizer I want to make the label height the same size as the text so I want to bring the gray or the label size down to the point where the gray is just surrounding the time Any ideas?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @nick_d12 You can use https://doc.qt.io/qt-6/qfontmetrics.html to determine the height of the text and then set fixed height for the label.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply
      1
      • jsulmJ jsulm

        @nick_d12 You can use https://doc.qt.io/qt-6/qfontmetrics.html to determine the height of the text and then set fixed height for the label.

        N Offline
        N Offline
        nick_d12
        wrote on last edited by
        #3

        @jsulm Hey thanks for the reply Unfortunately, for some reason that did not work I don't know if it is worth pointing out that I am using pyqt5 I am not sure if that changes anything, but I don't think so

        JonBJ N 2 Replies Last reply
        0
        • N nick_d12

          @jsulm Hey thanks for the reply Unfortunately, for some reason that did not work I don't know if it is worth pointing out that I am using pyqt5 I am not sure if that changes anything, but I don't think so

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

          @nick_d12 PyQt/Python should not matter, maybe show the code you tried?

          N 1 Reply Last reply
          0
          • JonBJ JonB

            @nick_d12 PyQt/Python should not matter, maybe show the code you tried?

            N Offline
            N Offline
            nick_d12
            wrote on last edited by
            #5

            @JonB ```
            def get_font_metrics(size):
            font = QFont("Nirmala UI Semilight", pointSize=size)
            font_metrics = QFontMetrics(font)
            text_height = font_metrics.height()
            return text_height

            
            I made this function to get the height of font them I use a fixed height based on the return value of this maybe I am using it wrong?
            1 Reply Last reply
            0
            • N nick_d12

              @jsulm Hey thanks for the reply Unfortunately, for some reason that did not work I don't know if it is worth pointing out that I am using pyqt5 I am not sure if that changes anything, but I don't think so

              N Offline
              N Offline
              nick_d12
              wrote on last edited by
              #6

              @JonB it works on text just fine however when it comes to numbers such as in the date not so much

              jsulmJ 1 Reply Last reply
              0
              • N nick_d12

                @JonB it works on text just fine however when it comes to numbers such as in the date not so much

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @nick_d12 Please use code tags correctly, especially when posting Python code.
                Is the font you're setting in QFont really the same used in the label? And what is the value get_font_metrics returns?
                Also, "that did not work" is not a proper problem description. In what way it did not work? Is the calculated height to big or to small?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1

                • Login

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