E5Gui/E5SqueezeLabels.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1131
7781e396c903
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
10 from PyQt4.QtCore import Qt 10 from PyQt4.QtCore import Qt
11 from PyQt4.QtGui import QLabel 11 from PyQt4.QtGui import QLabel
12 12
13 from Utilities import compactPath 13 from Utilities import compactPath
14 14
15
15 class E5SqueezeLabel(QLabel): 16 class E5SqueezeLabel(QLabel):
16 """ 17 """
17 Class implementing a label that squeezes its contents to fit it's size. 18 Class implementing a label that squeezes its contents to fit it's size.
18 """ 19 """
19 def __init__(self, parent = None): 20 def __init__(self, parent=None):
20 """ 21 """
21 Constructor 22 Constructor
22 23
23 @param parent reference to the parent Widget (QWidget) 24 @param parent reference to the parent Widget (QWidget)
24 """ 25 """
48 @param txt the text to be shown (string) 49 @param txt the text to be shown (string)
49 """ 50 """
50 self.__text = txt 51 self.__text = txt
51 QLabel.setText(self, self.__text) 52 QLabel.setText(self, self.__text)
52 53
54
53 class E5SqueezeLabelPath(QLabel): 55 class E5SqueezeLabelPath(QLabel):
54 """ 56 """
55 Class implementing a label showing a file path compacted to fit it's size. 57 Class implementing a label showing a file path compacted to fit it's size.
56 """ 58 """
57 def __init__(self, parent = None): 59 def __init__(self, parent=None):
58 """ 60 """
59 Constructor 61 Constructor
60 62
61 @param parent reference to the parent Widget (QWidget) 63 @param parent reference to the parent Widget (QWidget)
62 """ 64 """
100 102
101 @param event reference to the paint event (QPaintEvent) 103 @param event reference to the paint event (QPaintEvent)
102 """ 104 """
103 fm = self.fontMetrics() 105 fm = self.fontMetrics()
104 if fm.width(self.__surrounding.format(self.__path)) > self.contentsRect().width(): 106 if fm.width(self.__surrounding.format(self.__path)) > self.contentsRect().width():
105 QLabel.setText(self, 107 QLabel.setText(self,
106 self.__surrounding.format(compactPath(self.__path, 108 self.__surrounding.format(compactPath(self.__path,
107 self.contentsRect().width(), 109 self.contentsRect().width(),
108 self.length)) 110 self.length))
109 ) 111 )
110 else: 112 else:
111 QLabel.setText(self, self.__surrounding.format(self.__path)) 113 QLabel.setText(self, self.__surrounding.format(self.__path))
112 QLabel.paintEvent(self, event) 114 QLabel.paintEvent(self, event)

eric ide

mercurial