Text In Label Not Aligning Properly
-
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.!
JCdef 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 ############
-
Hi @Jonathan-C ,
Looking at your code, I assume you tried adding the "padding: 0px 5px 10px 15px" property to the StyleSheet, right?
Regards
-
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)
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)
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...