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. Text In Label Not Aligning Properly
QtWS25 Last Chance

Text In Label Not Aligning Properly

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 886 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.
  • J Offline
    J Offline
    Jonathan C
    wrote on 28 Jun 2022, 14:19 last edited by
    #1

    Hello there. Don't post to forums that often so sorry for any mislabeled or misformatted postings.
    Anyway, I'm working on a GUI that will run on a (most likely) a Raspberry Pi connected to a screen. This is my first true GUI. It is real simple as it only has 3 labels. I was able to get "speed" label (the label with the text "RUN" in the picture) aligned properly in the lower right corner, but I can't get the "speed unit" label to do the same in the upper right corner. Below is the code for setting up those 2 labels. The white border is only there to see where in the label the text is. Thanks in advanced and let me know if you have any other questions. And the commented sections are things I've tried and development code.!
    JC

    Screenshot from 2022-06-28 16-18-24.png

    def set_up_Speed_Unit_label(self):
            ### Speed Unit Label ###
            self.speed_unit_label = QLabel("KPH")
            self.speed_unit_label.setFont(self.sarabun_font)
            self.speed_unit_label.adjustSize()   # NOT SURE THIS IS NEEDED
            self.speed_unit_label.setStyleSheet("color: darkgrey;\
                                                    padding-right: 0 px;\
                                                    border: 1px solid white;")   # BORDER IS FOR DEBUGGING
                                                    #text-align: right;\
                                                    #padding-top: 0 px;")   # lightslategray is also good, slightly bluer
            self.speed_unit_label.setAlignment(Qt.AlignRight | Qt.AlignTop)
    
    def set_up_Speed_label(self):
            ### Speed Label ###
            self.speed_label = QLabel("RUN")
            self.speed_label.setFont(self.seg_font)
            self.speed_label.adjustSize()   # NOT SURE THIS IS NEEDED?????????????
            self.speed_label.setStyleSheet("""
                margin: 0px;
                padding: 0px;
                color: white;
                font-style: italic;
            """)   # BORDER IS FOR DEBUGGING
                #vertical-align: bottom;
                #border-width: 1px;
                #border-color: white;
                #border-style: solid;
            self.speed_label.setAlignment(Qt.AlignRight | Qt.AlignBottom)
            #self.check_font_size()  # RIGHT NOW FOR DEBUGGING OF FONT SIZE ############
    
    N 1 Reply Last reply 28 Jun 2022, 14:47
    0
    • J Jonathan C
      28 Jun 2022, 14:19

      Hello there. Don't post to forums that often so sorry for any mislabeled or misformatted postings.
      Anyway, I'm working on a GUI that will run on a (most likely) a Raspberry Pi connected to a screen. This is my first true GUI. It is real simple as it only has 3 labels. I was able to get "speed" label (the label with the text "RUN" in the picture) aligned properly in the lower right corner, but I can't get the "speed unit" label to do the same in the upper right corner. Below is the code for setting up those 2 labels. The white border is only there to see where in the label the text is. Thanks in advanced and let me know if you have any other questions. And the commented sections are things I've tried and development code.!
      JC

      Screenshot from 2022-06-28 16-18-24.png

      def set_up_Speed_Unit_label(self):
              ### Speed Unit Label ###
              self.speed_unit_label = QLabel("KPH")
              self.speed_unit_label.setFont(self.sarabun_font)
              self.speed_unit_label.adjustSize()   # NOT SURE THIS IS NEEDED
              self.speed_unit_label.setStyleSheet("color: darkgrey;\
                                                      padding-right: 0 px;\
                                                      border: 1px solid white;")   # BORDER IS FOR DEBUGGING
                                                      #text-align: right;\
                                                      #padding-top: 0 px;")   # lightslategray is also good, slightly bluer
              self.speed_unit_label.setAlignment(Qt.AlignRight | Qt.AlignTop)
      
      def set_up_Speed_label(self):
              ### Speed Label ###
              self.speed_label = QLabel("RUN")
              self.speed_label.setFont(self.seg_font)
              self.speed_label.adjustSize()   # NOT SURE THIS IS NEEDED?????????????
              self.speed_label.setStyleSheet("""
                  margin: 0px;
                  padding: 0px;
                  color: white;
                  font-style: italic;
              """)   # BORDER IS FOR DEBUGGING
                  #vertical-align: bottom;
                  #border-width: 1px;
                  #border-color: white;
                  #border-style: solid;
              self.speed_label.setAlignment(Qt.AlignRight | Qt.AlignBottom)
              #self.check_font_size()  # RIGHT NOW FOR DEBUGGING OF FONT SIZE ############
      
      N Offline
      N Offline
      ndias
      wrote on 28 Jun 2022, 14:47 last edited by
      #2

      Hi @Jonathan-C ,

      Looking at your code, I assume you tried adding the "padding: 0px 5px 10px 15px" property to the StyleSheet, right?

      Regards

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jonathan C
        wrote on 29 Jun 2022, 06:52 last edited by
        #3

        Yes and it doesn't seem to do anything.

        def set_up_Speed_Unit_label(self):
                self.speed_unit_label = QLabel("KPH")
                self.speed_unit_label.setFont(self.sarabun_font)
                self.speed_unit_label.adjustSize()   # NOT SURE THIS IS NEEDED
                self.speed_unit_label.setStyleSheet("color: darkgrey;\
                                                        padding-right: 0 px;\
                                                        border: 1px solid white;\
                                                        text-align: right;")
                                                        #padding-top: 0 px;")
                #self.speed_unit_label.setAlignment(Qt.AlignRight | Qt.AlignTop)
        

        Screenshot from 2022-06-29 08-42-39.png

            def set_up_Speed_Unit_label(self):
                self.speed_unit_label = QLabel("KPH")
                self.speed_unit_label.setFont(self.sarabun_font)
                self.speed_unit_label.adjustSize()   # NOT SURE THIS IS NEEDED
                self.speed_unit_label.setStyleSheet("color: darkgrey;\
                                                        padding-right: 0 px;\
                                                        border: 1px solid white;\
                                                        padding-top: 0 px;")
                                                        #text-align: right;")
                self.speed_unit_label.setAlignment(Qt.AlignRight | Qt.AlignTop)
        

        Screenshot from 2022-06-29 08-43-01.png

        That's why I don't get it, I'm essentially copying the Speed Label (the RUN label) that does go to the right spot...

        1 Reply Last reply
        0

        1/3

        28 Jun 2022, 14:19

        • Login

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