本文整理匯總了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()