src/eric7/EricWidgets/EricLineEditButton.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
14 14
15 class EricLineEditButton(QAbstractButton): 15 class EricLineEditButton(QAbstractButton):
16 """ 16 """
17 Class implementing a button to be used with EricLineEdit. 17 Class implementing a button to be used with EricLineEdit.
18 """ 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 """
25 super().__init__(parent) 26 super().__init__(parent)
26 27
27 self.__menu = None 28 self.__menu = None
28 self.__image = None 29 self.__image = None
29 30
30 self.setFocusPolicy(Qt.FocusPolicy.NoFocus) 31 self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
31 self.setCursor(Qt.CursorShape.ArrowCursor) 32 self.setCursor(Qt.CursorShape.ArrowCursor)
32 self.setMinimumSize(16, 16) 33 self.setMinimumSize(16, 16)
33 34
34 self.clicked.connect(self.__clicked) 35 self.clicked.connect(self.__clicked)
35 36
36 def setMenu(self, menu): 37 def setMenu(self, menu):
37 """ 38 """
38 Public method to set the button menu. 39 Public method to set the button menu.
39 40
40 @param menu reference to the menu (QMenu) 41 @param menu reference to the menu (QMenu)
41 """ 42 """
42 self.__menu = menu 43 self.__menu = menu
43 self.update() 44 self.update()
44 45
45 def menu(self): 46 def menu(self):
46 """ 47 """
47 Public method to get a reference to the menu. 48 Public method to get a reference to the menu.
48 49
49 @return reference to the associated menu (QMenu) 50 @return reference to the associated menu (QMenu)
50 """ 51 """
51 return self.__menu 52 return self.__menu
52 53
53 def setIcon(self, icon): 54 def setIcon(self, icon):
54 """ 55 """
55 Public method to set the button icon. 56 Public method to set the button icon.
56 57
57 @param icon icon to be set (QIcon) 58 @param icon icon to be set (QIcon)
58 """ 59 """
59 if icon.isNull(): 60 if icon.isNull():
60 self.__image = None 61 self.__image = None
61 else: 62 else:
62 self.__image = icon.pixmap(16, 16).toImage() 63 self.__image = icon.pixmap(16, 16).toImage()
63 super().setIcon(icon) 64 super().setIcon(icon)
64 65
65 def __clicked(self): 66 def __clicked(self):
66 """ 67 """
67 Private slot to handle a button click. 68 Private slot to handle a button click.
68 """ 69 """
69 if self.__menu: 70 if self.__menu:
70 pos = self.mapToGlobal(QPoint(0, self.height())) 71 pos = self.mapToGlobal(QPoint(0, self.height()))
71 self.__menu.exec(pos) 72 self.__menu.exec(pos)
72 73
73 def paintEvent(self, evt): 74 def paintEvent(self, evt):
74 """ 75 """
75 Protected method handling a paint event. 76 Protected method handling a paint event.
76 77
77 @param evt reference to the paint event (QPaintEvent) 78 @param evt reference to the paint event (QPaintEvent)
78 """ 79 """
79 painter = QPainter(self) 80 painter = QPainter(self)
80 81
81 if self.__image is not None and not self.__image.isNull(): 82 if self.__image is not None and not self.__image.isNull():
82 x = (self.width() - self.__image.width()) // 2 - 1 83 x = (self.width() - self.__image.width()) // 2 - 1
83 y = (self.height() - self.__image.height()) // 2 - 1 84 y = (self.height() - self.__image.height()) // 2 - 1
84 painter.drawImage(x, y, self.__image) 85 painter.drawImage(x, y, self.__image)
85 86
86 if self.__menu is not None: 87 if self.__menu is not None:
87 triagPath = QPainterPath() 88 triagPath = QPainterPath()
88 startPos = QPointF(self.width() - 5, self.height() - 3) 89 startPos = QPointF(self.width() - 5, self.height() - 3)
89 triagPath.moveTo(startPos) 90 triagPath.moveTo(startPos)
90 triagPath.lineTo(startPos.x() + 4, startPos.y()) 91 triagPath.lineTo(startPos.x() + 4, startPos.y())

eric ide

mercurial