本文整理汇总了Python中python_qt_binding.QtGui.QPushButton.toggle方法的典型用法代码示例。如果您正苦于以下问题:Python QPushButton.toggle方法的具体用法?Python QPushButton.toggle怎么用?Python QPushButton.toggle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类python_qt_binding.QtGui.QPushButton
的用法示例。
在下文中一共展示了QPushButton.toggle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TimelineWidget
# 需要导入模块: from python_qt_binding.QtGui import QPushButton [as 别名]
# 或者: from python_qt_binding.QtGui.QPushButton import toggle [as 别名]
class TimelineWidget(QWidget):
class TimelineView(QGraphicsView):
def __init__(self, parent):
super(TimelineWidget.TimelineView, self).__init__()
self.parent = parent
def mouseReleaseEvent(self, event):
self.parent.mouse_release(event)
update = pyqtSignal()
def __init__(self, parent):
super(TimelineWidget, self).__init__()
self.parent = parent
self._layout = QHBoxLayout()
#self._view = QGraphicsView()
self._view = TimelineWidget.TimelineView(self)
self._scene = QGraphicsScene()
self._colors = [QColor('green'), QColor('yellow'), QColor('red')]
self._messages = [None for x in range(20)]
self._mq = [1 for x in range(20)]
self._view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._view.setScene(self._scene)
self._layout.addWidget(self._view, 1)
self.pause_button = QPushButton('Pause')
self.pause_button.setCheckable(True)
self.pause_button.clicked.connect(self.pause)
self._layout.addWidget(self.pause_button)
self.setLayout(self._layout)
self.update.connect(self.redraw)
def redraw(self):
self._scene.clear()
self._scene
for i, m in enumerate(self._mq):
w = float(self._view.viewport().width())/len(self._mq)
h = self._view.viewport().height()
rect = self._scene.addRect(w*i, 0, w, h, QColor('black'), self._colors[m])
def mouse_release(self, event):
i = int(floor(event.x()/(float(self._view.viewport().width())/len(self._mq))))
msg = self._messages[i]
if msg:
self.parent.pause(msg)
if not self.pause_button.isChecked():
self.pause_button.toggle()
def resizeEvent(self, event):
self.redraw()
def get_worst(self, msg):
lvl = 0
for status in msg.status:
if status.level > lvl:
lvl = status.level
return lvl
def add_message(self, msg):
self._messages = self._messages[1:]
self._messages.append(msg)
self._mq = self._mq[1:]
try:
lvl = msg.level
except AttributeError:
lvl = self.get_worst(msg)
if lvl > 2:
lvl = 2
self._mq.append(lvl)
self.update.emit()
def pause(self, state):
if state:
self.parent.pause(self._messages[-1])
else:
self.parent.unpause()