Commit 4dc6ec55 authored by Damien Naudet's avatar Damien Naudet

Using setFixedWidth instead of stylesheet.

parent 4310e19a
...@@ -113,15 +113,13 @@ class StyledLineEdit(Qt.QLineEdit): ...@@ -113,15 +113,13 @@ class StyledLineEdit(Qt.QLineEdit):
return super(StyledLineEdit, self).event(ev) return super(StyledLineEdit, self).event(ev)
class StyledLabel(Qt.QLabel): class FixedSizeLabel(Qt.QLabel):
""" """
Styled QLabel. Styled QLabel.
""" """
_padding = 2
def __init__(self, parent=None, nChar=None): def __init__(self, parent=None, nChar=None):
super(StyledLabel, self).__init__(parent) super(FixedSizeLabel, self).__init__(parent)
self.__nChar = nChar self.__nChar = nChar
self.setAlignment(Qt.Qt.AlignLeft) self.setAlignment(Qt.Qt.AlignLeft)
self.setFrameStyle(Qt.QFrame.Panel | Qt.QFrame.Sunken) self.setFrameStyle(Qt.QFrame.Panel | Qt.QFrame.Sunken)
...@@ -141,17 +139,10 @@ class StyledLabel(Qt.QLabel): ...@@ -141,17 +139,10 @@ class StyledLabel(Qt.QLabel):
Sets the style sheet. Sets the style sheet.
:return: :return:
""" """
sheet = ''
if self.__nChar is not None: if self.__nChar is not None:
# There are two stylesheet units "em" and "xm" that I tried,
# but the results were not satisfactory.
fm = self.fontMetrics() fm = self.fontMetrics()
width = fm.width('M') * self.__nChar
height = fm.height() # see QLabel::indent doc for the reason behind the width('x')/2
sheet += """StyledLabel{{ max-width: {0}px; width = fm.width('M') * self.__nChar + (fm.width('x') / 2)
min-width: {0}px; self.setFixedWidth(width)
max-height: {1}px;
min-height: {1}px;}}
""".format(width, height)
self.setStyleSheet(sheet)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment