本文整理汇总了Python中python_qt_binding.QtGui.QApplication.sendPostedEvents方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.sendPostedEvents方法的具体用法?Python QApplication.sendPostedEvents怎么用?Python QApplication.sendPostedEvents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类python_qt_binding.QtGui.QApplication
的用法示例。
在下文中一共展示了QApplication.sendPostedEvents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _event
# 需要导入模块: from python_qt_binding.QtGui import QApplication [as 别名]
# 或者: from python_qt_binding.QtGui.QApplication import sendPostedEvents [as 别名]
def _event(self, e):
if e.type() == QEvent.MouseButtonPress and e.button() == Qt.LeftButton:
qDebug('%spress, rel=%s, global=%s, diff=%s' % ((' - pseudo ' if self._releasing_and_repressing_while_dragging else ''), e.pos(), e.globalPos(), e.globalPos() - self.pos()))
if e.type() == QEvent.MouseButtonRelease and e.button() == Qt.LeftButton:
qDebug('%srelease, rel=%s, global=%s, diff=%s' % ((' - pseudo ' if self._releasing_and_repressing_while_dragging else ''), e.pos(), e.globalPos(), e.globalPos() - self.pos()))
# store local position when pressing button before starting the custom drag'n'drop
# only allow when layout is not frozen
if self._dragging_parent is None and e.type() == QEvent.MouseButtonPress and e.button() == Qt.LeftButton and bool(self.features() & QDockWidget.DockWidgetMovable):
self._dragging_local_pos = e.pos()
if self._dragging_parent is None and self._dragging_local_pos is not None and e.type() == QEvent.Move and QApplication.mouseButtons() & Qt.LeftButton:
if self._widget_at(e.pos()) is not None:
qDebug('DockWidget._event() start drag, dockwidget=%s, parent=%s, floating=%s, pos=%s' % (str(self), str(self.parent()), str(self.isFloating()), str(self._dragging_local_pos)))
self._dragging_parent = self.parent()
# ignore further mouse events so that the widget behind this dock widget can be determined
self.setAttribute(Qt.WA_TransparentForMouseEvents)
# collect all main windows (except self.main_window) to re-implement QApplication.widgetAt() in self._widget_at()
self._main_windows = [self._container_manager.get_root_main_window()]
for container in self._container_manager.get_containers():
if container == self:
continue
self._main_windows.append(container.main_window)
# unset local position when releasing button even when custom drag'n'drop has not been started
if self._dragging_local_pos is not None and e.type() == QEvent.MouseButtonRelease and e.button() == Qt.LeftButton and not self._releasing_and_repressing_while_dragging:
self._dragging_local_pos = None
if self._dragging_parent is not None and e.type() == QEvent.MouseButtonRelease and e.button() == Qt.LeftButton and not self._releasing_and_repressing_while_dragging:
qDebug('DockWidget._event() stop drag, dockwidget=%s, parent=%s\n' % (self, self.parent()))
self._dragging_parent = None
self.setAttribute(Qt.WA_TransparentForMouseEvents, False)
self._main_windows = []
if self._dragging_parent is not None and e.type() == QEvent.MouseMove and e.buttons() & Qt.LeftButton and not self._releasing_and_repressing_while_dragging:
widget = self._widget_at(e.globalPos())
new_parent = self._get_new_parent(widget)
#print 'new_parent', new_parent, (new_parent.objectName() if new_parent else '')
if new_parent is not None and new_parent != self.parent():
self._releasing_and_repressing_while_dragging = True
# schedule stop of pseudo drag'n'drop and let it complete
mouse_release_event = QMouseEvent(QEvent.MouseButtonRelease, self._dragging_local_pos, e.globalPos(), Qt.LeftButton, Qt.NoButton, e.modifiers())
QApplication.instance().postEvent(self, mouse_release_event)
QApplication.sendPostedEvents()
# schedule reparent to hovered main window and let it complete
reparent_event = ReparentEvent(self, new_parent)
QApplication.instance().postEvent(self._container_manager, reparent_event)
QApplication.sendPostedEvents()
# reenable mouse events to be able to receive upcoming pseudo mouse events
self.setAttribute(Qt.WA_TransparentForMouseEvents, False)
# schedule restart of pseudo drag'n'drop and let it complete
mouse_repress_event = QMouseEvent(QEvent.MouseButtonPress, self._dragging_local_pos, e.globalPos(), Qt.LeftButton, Qt.LeftButton, e.modifiers())
QApplication.instance().postEvent(self, mouse_repress_event)
QApplication.sendPostedEvents()
# schedule move to trigger dock widget drag'n'drop required for snapping and showing rubber band and let it complete
# move forth...
mouse_move_event = QMouseEvent(QEvent.MouseMove, self._dragging_local_pos, e.globalPos() + QPoint(QApplication.startDragDistance(), 1), Qt.NoButton, Qt.LeftButton, e.modifiers())
QApplication.instance().postEvent(self, mouse_move_event)
QApplication.sendPostedEvents()
# ...and back
mouse_move_event = QMouseEvent(QEvent.MouseMove, self._dragging_local_pos, e.globalPos(), Qt.NoButton, Qt.LeftButton, e.modifiers())
QApplication.instance().postEvent(self, mouse_move_event)
QApplication.sendPostedEvents()
# restore attributes after repressing the button
self.setAttribute(Qt.WA_TransparentForMouseEvents)
self._releasing_and_repressing_while_dragging = False
return super(DockWidget, self).event(e)