本文整理汇总了Python中PyQt5.QtCore.Qt.LeftButton方法的典型用法代码示例。如果您正苦于以下问题:Python Qt.LeftButton方法的具体用法?Python Qt.LeftButton怎么用?Python Qt.LeftButton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.Qt
的用法示例。
在下文中一共展示了Qt.LeftButton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: text_mousePressEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def text_mousePressEvent(self, e):
if e.button() == Qt.LeftButton and self.current_pos is None:
self.current_pos = e.pos()
self.current_text = ""
self.timer_event = self.text_timerEvent
elif e.button() == Qt.LeftButton:
self.timer_cleanup()
# Draw the text to the image
p = QPainter(self.pixmap())
p.setRenderHints(QPainter.Antialiasing)
font = build_font(self.config)
p.setFont(font)
pen = QPen(self.primary_color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
p.setPen(pen)
p.drawText(self.current_pos, self.current_text)
self.update()
self.reset_mode()
elif e.button() == Qt.RightButton and self.current_pos:
self.reset_mode()
示例2: editorEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def editorEvent(self, event, model, option, index):
'''
Handle mouse events in cell.
On left button release in this cell, call model's setData() method,
wherein the button clicked action should be handled.
Currently, the value supplied to setData() is the button text, but this is arbitrary.
'''
if event.button() == Qt.LeftButton:
if event.type() == QEvent.MouseButtonPress:
if option.rect.contains(event.pos()):
self._isMousePressed = True
return True
elif event.type() == QEvent.MouseButtonRelease:
self._isMousePressed = False
if option.rect.contains(event.pos()):
model.setData(index, self.text, Qt.EditRole) # Model should handle button click action in its setData() method.
return True
return False
示例3: editorEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def editorEvent(self, event, model, option, index):
'''
Change the data in the model and the state of the checkbox if the
user presses the left mouse button and this cell is editable. Otherwise do nothing.
'''
if not (index.flags() & Qt.ItemIsEditable):
return False
if event.button() == Qt.LeftButton:
if event.type() == QEvent.MouseButtonRelease:
if self.getCheckBoxRect(option).contains(event.pos()):
self.setModelData(None, model, index)
return True
elif event.type() == QEvent.MouseButtonDblClick:
if self.getCheckBoxRect(option).contains(event.pos()):
return True
return False
示例4: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mouseMoveEvent(self,event):
pos = event.pos()
x,y = pos.x(),pos.y()
if event.buttons() == Qt.LeftButton:
self.view.Rotation(x,y)
elif event.buttons() == Qt.MiddleButton:
self.view.Pan(x - self.old_pos.x(),
self.old_pos.y() - y, theToStart=True)
elif event.buttons() == Qt.RightButton:
self.view.ZoomAtPoint(self.old_pos.x(), y,
x, self.old_pos.y())
self.old_pos = pos
示例5: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mouseMoveEvent(self, event):
if (event.buttons() == Qt.LeftButton and
(event.modifiers() == Qt.ControlModifier or
event.modifiers() == Qt.ShiftModifier)):
mime_data = QMimeData()
mime_data.setText(PageWidget.DRAG_MAGIC)
drag = QDrag(self)
drag.setMimeData(mime_data)
drag.setPixmap(self.grab(self.rect()))
if event.modifiers() == Qt.ControlModifier:
drag.exec_(Qt.MoveAction)
else:
drag.exec_(Qt.CopyAction)
event.accept()
else:
event.ignore()
示例6: mousePressEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mousePressEvent(self, e):
cr = self._control_rect()
if e.button() == Qt.LeftButton and not cr.contains(e.pos()):
# Set the value to the minimum
value = self.minimum()
# zmax is the maximum value starting from zero
zmax = self.maximum() - self.minimum()
if self.orientation() == Qt.Vertical:
# Add the current position multiplied for value/size ratio
value += (self.height() - e.y()) * (zmax / self.height())
else:
value += e.x() * (zmax / self.width())
if self.value() != value:
self.setValue(value)
self.sliderJumped.emit(self.value())
e.accept()
else:
e.ignore()
else:
super().mousePressEvent(e)
示例7: mouseReleaseEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mouseReleaseEvent(self, event):
""" Stop mouse pan or zoom mode (apply zoom if valid).
"""
QGraphicsView.mouseReleaseEvent(self, event)
scenePos = self.mapToScene(event.pos())
if event.button() == Qt.LeftButton:
self.setDragMode(QGraphicsView.NoDrag)
self.leftMouseButtonReleased.emit(scenePos.x(), scenePos.y())
elif event.button() == Qt.RightButton:
if self.canZoom:
viewBBox = self.zoomStack[-1] if len(self.zoomStack) else self.sceneRect()
selectionBBox = self.scene.selectionArea().boundingRect().intersected(viewBBox)
self.scene.setSelectionArea(QPainterPath()) # Clear current selection area.
if selectionBBox.isValid() and (selectionBBox != viewBBox):
self.zoomStack.append(selectionBBox)
self.updateViewer()
self.setDragMode(QGraphicsView.NoDrag)
self.rightMouseButtonReleased.emit(scenePos.x(), scenePos.y())
示例8: mousePressEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mousePressEvent(self, ev):
ctrl, shift = self._GetCtrlShift(ev)
repeat = 0
if ev.type() == QEvent.MouseButtonDblClick:
repeat = 1
self._Iren.SetEventInformationFlipY(ev.x(), ev.y(),
ctrl, shift, chr(0), repeat, None)
self._ActiveButton = ev.button()
if self._ActiveButton == Qt.LeftButton:
self._Iren.LeftButtonPressEvent()
elif self._ActiveButton == Qt.RightButton:
self._Iren.RightButtonPressEvent()
elif self._ActiveButton == Qt.MidButton:
self._Iren.MiddleButtonPressEvent()
示例9: mousePressEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mousePressEvent(self, event):
logging.debug('ElementMaster::mousePressEvent() called')
# uncomment this for debugging purpose
#self.listChild()
if event.buttons() != Qt.LeftButton:
return
icon = QLabel()
mimeData = QMimeData()
mime_text = str(self.row) + str(self.column) + str(self.__class__.__name__)
mimeData.setText(mime_text)
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setPixmap(self.pixmap)
drag.setHotSpot(event.pos() - self.rect().topLeft())
if drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction:
icon.close()
else:
icon.show()
icon.setPixmap(self.pixmap)
示例10: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mouseMoveEvent(self, event):
if self.win.windowState() == Qt.WindowNoState:
self.nheight = self.win.geometry().height()
if event.buttons() == Qt.LeftButton and self.mPos:
if event.pos() == self.mPos:
return
if self.win.windowState() == Qt.WindowMaximized:
MaxWinWidth = self.width() # 窗口最大化宽度
WinX = self.win.geometry().x() # 窗口屏幕左上角x坐标
self.win.showNormal()
self.buttonMaximum.setText('1')
# 还原后的窗口宽和高
nwidth = self.width()
nheight = self.nheight
x, y = event.globalPos().x(), event.globalPos().y()
x = x - nwidth * (x-WinX)/MaxWinWidth
self.win.setGeometry(x, 1, nwidth, nheight)
return
movePos = event.globalPos() - self.mPos
self.mPos = event.globalPos()
self.win.move(self.win.pos() + movePos)
return QWidget().mouseMoveEvent(event)
示例11: _click_fake_event
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def _click_fake_event(self, click_target: usertypes.ClickTarget,
button: Qt.MouseButton = Qt.LeftButton) -> None:
self._tab.data.override_target = click_target
super()._click_fake_event(click_target)
示例12: _click_fake_event
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def _click_fake_event(self, click_target: usertypes.ClickTarget,
button: Qt.MouseButton = Qt.LeftButton) -> None:
"""Send a fake click event to the element."""
pos = self._mouse_pos()
log.webelem.debug("Sending fake click to {!r} at position {} with "
"target {}".format(self, pos, click_target))
target_modifiers = {
usertypes.ClickTarget.normal: Qt.NoModifier,
usertypes.ClickTarget.window: Qt.AltModifier | Qt.ShiftModifier,
usertypes.ClickTarget.tab: Qt.ControlModifier,
usertypes.ClickTarget.tab_bg: Qt.ControlModifier,
}
if config.val.tabs.background:
target_modifiers[usertypes.ClickTarget.tab] |= Qt.ShiftModifier
else:
target_modifiers[usertypes.ClickTarget.tab_bg] |= Qt.ShiftModifier
modifiers = typing.cast(Qt.KeyboardModifiers,
target_modifiers[click_target])
events = [
QMouseEvent(QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton,
Qt.NoModifier),
QMouseEvent(QEvent.MouseButtonPress, pos, button, button,
modifiers),
QMouseEvent(QEvent.MouseButtonRelease, pos, button, Qt.NoButton,
modifiers),
]
for evt in events:
self._tab.send_event(evt)
QTimer.singleShot(0, self._move_text_cursor)
示例13: _handle_mouse_press
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def _handle_mouse_press(self, e):
"""Handle pressing of a mouse button.
Args:
e: The QMouseEvent.
Return:
True if the event should be filtered, False otherwise.
"""
is_rocker_gesture = (config.val.input.mouse.rocker_gestures and
e.buttons() == Qt.LeftButton | Qt.RightButton)
if e.button() in [Qt.XButton1, Qt.XButton2] or is_rocker_gesture:
self._mousepress_backforward(e)
return True
self._ignore_wheel_event = True
pos = e.pos()
if pos.x() < 0 or pos.y() < 0:
log.mouse.warning("Ignoring invalid click at {}".format(pos))
return False
if e.button() != Qt.NoButton:
self._tab.elements.find_at_pos(pos, self._mousepress_insertmode_cb)
return False
示例14: _mousepress_backforward
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def _mousepress_backforward(self, e):
"""Handle back/forward mouse button presses.
Args:
e: The QMouseEvent.
Return:
True if the event should be filtered, False otherwise.
"""
if (not config.val.input.mouse.back_forward_buttons and
e.button() in [Qt.XButton1, Qt.XButton2]):
# Back and forward on mice are disabled
return
if e.button() in [Qt.XButton1, Qt.LeftButton]:
# Back button on mice which have it, or rocker gesture
if self._tab.history.can_go_back():
self._tab.history.back()
else:
message.error("At beginning of history.")
elif e.button() in [Qt.XButton2, Qt.RightButton]:
# Forward button on mice which have it, or rocker gesture
if self._tab.history.can_go_forward():
self._tab.history.forward()
else:
message.error("At end of history.")
示例15: mousePressEvent
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import LeftButton [as 别名]
def mousePressEvent(self, e):
"""Toggle the fold if the widget was pressed.
Args:
e: The QMouseEvent.
"""
if e.button() == Qt.LeftButton:
e.accept()
self.toggle()
else:
super().mousePressEvent(e)