7 Module implementing a specialized tool button subclass. |
7 Module implementing a specialized tool button subclass. |
8 """ |
8 """ |
9 |
9 |
10 |
10 |
11 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QTimer, QSize |
11 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QTimer, QSize |
12 from PyQt5.QtWidgets import QToolButton, QStyle, QStyleOptionToolButton, \ |
12 from PyQt5.QtWidgets import ( |
13 QStyleOption, QApplication, QLabel |
13 QToolButton, QStyle, QStyleOptionToolButton, QStyleOption, QApplication, |
|
14 QLabel |
|
15 ) |
14 |
16 |
15 |
17 |
16 class E5ToolButton(QToolButton): |
18 class E5ToolButton(QToolButton): |
17 """ |
19 """ |
18 Class implementing a specialized tool button subclass. |
20 Class implementing a specialized tool button subclass. |
195 @type QMouseEvent |
197 @type QMouseEvent |
196 """ |
198 """ |
197 if self.popupMode() == QToolButton.DelayedPopup: |
199 if self.popupMode() == QToolButton.DelayedPopup: |
198 self.__pressTimer.start() |
200 self.__pressTimer.start() |
199 |
201 |
200 if evt.buttons() == Qt.LeftButton and \ |
202 if ( |
201 self.__menu is not None and \ |
203 evt.buttons() == Qt.LeftButton and |
202 self.popupMode() == QToolButton.InstantPopup: |
204 self.__menu is not None and |
|
205 self.popupMode() == QToolButton.InstantPopup |
|
206 ): |
203 self.setDown(True) |
207 self.setDown(True) |
204 self.__showMenu() |
208 self.__showMenu() |
205 elif evt.buttons() == Qt.RightButton and \ |
209 elif ( |
206 self.__menu is not None: |
210 evt.buttons() == Qt.RightButton and |
|
211 self.__menu is not None |
|
212 ): |
207 self.setDown(True) |
213 self.setDown(True) |
208 self.__showMenu() |
214 self.__showMenu() |
209 else: |
215 else: |
210 super(E5ToolButton, self).mousePressEvent(evt) |
216 super(E5ToolButton, self).mousePressEvent(evt) |
211 |
217 |
216 @param evt reference to the mouse event |
222 @param evt reference to the mouse event |
217 @type QMouseEvent |
223 @type QMouseEvent |
218 """ |
224 """ |
219 self.__pressTimer.stop() |
225 self.__pressTimer.stop() |
220 |
226 |
221 if evt.button() == Qt.MiddleButton and \ |
227 if ( |
222 self.rect().contains(evt.pos()): |
228 evt.button() == Qt.MiddleButton and |
|
229 self.rect().contains(evt.pos()) |
|
230 ): |
223 self.middleClicked.emit() |
231 self.middleClicked.emit() |
224 self.setDown(False) |
232 self.setDown(False) |
225 elif evt.button() == Qt.LeftButton and \ |
233 elif ( |
226 self.rect().contains(evt.pos()) and \ |
234 evt.button() == Qt.LeftButton and |
227 evt.modifiers() == Qt.ControlModifier: |
235 self.rect().contains(evt.pos()) and |
|
236 evt.modifiers() == Qt.ControlModifier |
|
237 ): |
228 self.controlClicked.emit() |
238 self.controlClicked.emit() |
229 self.setDown(False) |
239 self.setDown(False) |
230 else: |
240 else: |
231 super(E5ToolButton, self).mouseReleaseEvent(evt) |
241 super(E5ToolButton, self).mouseReleaseEvent(evt) |
232 |
242 |