本文整理汇总了Python中enaml.qt.QtGui.QApplication.desktop方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.desktop方法的具体用法?Python QApplication.desktop怎么用?Python QApplication.desktop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enaml.qt.QtGui.QApplication
的用法示例。
在下文中一共展示了QApplication.desktop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ensure_on_screen
# 需要导入模块: from enaml.qt.QtGui import QApplication [as 别名]
# 或者: from enaml.qt.QtGui.QApplication import desktop [as 别名]
def ensure_on_screen(rect):
""" Ensure that the given rect is contained on screen.
If the origin of the rect is not contained within the closest
desktop screen, the rect will be moved so that it is fully on the
closest screen. If the rect is larger than the closest screen, the
origin will never be less than the screen origin.
Parameters
----------
rect : QRect
The geometry rect of interest.
Returns
-------
result : QRect
The potentially adjusted QRect which fits on the screen.
"""
d = QApplication.desktop()
pos = rect.topLeft()
drect = d.screenGeometry(pos)
if not drect.contains(pos):
x = pos.x()
if x < drect.x() or x > drect.right():
dw = drect.width() - rect.width()
x = max(drect.x(), drect.x() + dw)
y = pos.y()
if x < drect.top() or y > drect.bottom():
dh = drect.height() - rect.height()
y = max(drect.y(), drect.y() + dh)
rect = QRect(x, y, rect.width(), rect.height())
return rect
示例2: snapshot
# 需要导入模块: from enaml.qt.QtGui import QApplication [as 别名]
# 或者: from enaml.qt.QtGui.QApplication import desktop [as 别名]
def snapshot(self):
""" Take a snapshot of the window and close it.
"""
widget = self.view.proxy.widget
framesize = widget.window().frameSize()
QPixmap.grabWindow(QApplication.desktop().winId(), widget.x(),
widget.y(), framesize.width(),
framesize.height() ).save(self.path)
widget.close()