本文整理汇总了Python中PyQt5.QtCore.QRect方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QRect方法的具体用法?Python QtCore.QRect怎么用?Python QtCore.QRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveScreenshot
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def saveScreenshot(self, clipboard=False, fileName='screenshot.png', picType='png'):
fullWindow = QRect(0, 0, self.width() - 1, self.height() - 1)
selected = QRect(self.selected_area)
if selected.left() < 0:
selected.setLeft(0)
if selected.right() >= self.width():
selected.setRight(self.width() - 1)
if selected.top() < 0:
selected.setTop(0)
if selected.bottom() >= self.height():
selected.setBottom(self.height() - 1)
source = (fullWindow & selected)
source.setTopLeft(QPoint(source.topLeft().x() * self.scale, source.topLeft().y() * self.scale))
source.setBottomRight(QPoint(source.bottomRight().x() * self.scale, source.bottomRight().y() * self.scale))
image = self.screenPixel.copy(source)
if clipboard:
QGuiApplication.clipboard().setImage(QImage(image), QClipboard.Clipboard)
else:
image.save(fileName, picType, 10)
self.target_img = image
self.screen_shot_grabed.emit(QImage(image))
示例2: drawSizeInfo
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def drawSizeInfo(self):
sizeInfoAreaWidth = 200
sizeInfoAreaHeight = 30
spacing = 5
rect = self.selected_area.normalized()
sizeInfoArea = QRect(rect.left(), rect.top() - spacing - sizeInfoAreaHeight,
sizeInfoAreaWidth, sizeInfoAreaHeight)
if sizeInfoArea.top() < 0:
sizeInfoArea.moveTopLeft(rect.topLeft() + QPoint(spacing, spacing))
if sizeInfoArea.right() >= self.screenPixel.width():
sizeInfoArea.moveTopLeft(rect.topLeft() - QPoint(spacing, spacing) - QPoint(sizeInfoAreaWidth, 0))
if sizeInfoArea.left() < spacing:
sizeInfoArea.moveLeft(spacing)
if sizeInfoArea.top() < spacing:
sizeInfoArea.moveTop(spacing)
self.items_to_remove.append(self.graphics_scene.addRect(QRectF(sizeInfoArea), Qt.white, QBrush(Qt.black)))
sizeInfo = self.graphics_scene.addSimpleText(
' {0} x {1}'.format(rect.width() * self.scale, rect.height() * self.scale))
sizeInfo.setPos(sizeInfoArea.topLeft() + QPoint(0, 2))
sizeInfo.setPen(QPen(QColor(255, 255, 255), 2))
self.items_to_remove.append(sizeInfo)
示例3: paintEvent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def paintEvent(self, event):
QtWidgets.QFrame.paintEvent(self, event)
painter = QtGui.QPainter()
painter.begin(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
# Draw the Pie
rwidth = int(min([self.width(), self.height()]) - 2)
x = int((self.width() / 2) - (rwidth / 2))
y = int((self.height() / 2) - (rwidth / 2))
rect = QtCore.QRect(x, y, rwidth, rwidth)
angle1 = 0
for i in range(len(self.data)):
angle2 = angle1 + (3.6 * self.data[i])
painter.setBrush(QtGui.QBrush(self.colors[i % len(self.colors)]))
painter.drawPie(rect, angle1*-16, (angle2-angle1)*-16)
angle1 = angle2
# Draw the remainer (background)
angle2 = 360
painter.setBrush(QtGui.QBrush(self.bgcolor))
painter.drawPie(rect, angle1*-16, (angle2-angle1)*-16)
painter.end()
示例4: test_iframe
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def test_iframe(self, stubs, js_rect):
"""Test an element in an iframe.
0, 0 200, 0
##############################
# #
0,10 # iframe 100,10 #
#********** #
#* * #
#* * #
#* e * elem: 20,90 in iframe
#********** #
0,100 # #
##############################
200, 0 200, 200
"""
frame = stubs.FakeWebFrame(QRect(0, 0, 200, 200))
iframe = stubs.FakeWebFrame(QRect(0, 10, 100, 100), parent=frame)
assert frame.geometry().contains(iframe.geometry())
elem = get_webelem(QRect(20, 90, 10, 10), iframe,
js_rect_return=js_rect)
assert elem.rect_on_view() == QRect(20, 10 + 90, 10, 10)
示例5: setupUi
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def setupUi(self, ScoreWindow):
ScoreWindow.setObjectName("ScoreWindow")
ScoreWindow.resize(471, 386)
self.centralwidget = QtWidgets.QWidget(ScoreWindow)
self.centralwidget.setObjectName("centralwidget")
self.Score = QtWidgets.QLineEdit(self.centralwidget)
self.Score.setGeometry(QtCore.QRect(180, 180, 113, 22))
self.Score.setObjectName("Score")
self.teamscore = QtWidgets.QLabel(self.centralwidget)
self.teamscore.setGeometry(QtCore.QRect(180, 130, 151, 20))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.teamscore.setFont(font)
self.teamscore.setObjectName("teamscore")
ScoreWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(ScoreWindow)
self.statusbar.setObjectName("statusbar")
ScoreWindow.setStatusBar(self.statusbar)
self.retranslateUi(ScoreWindow)
QtCore.QMetaObject.connectSlotsByName(ScoreWindow)
示例6: setupUi
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def setupUi(self, QHangupsConversationsList):
QHangupsConversationsList.setObjectName("QHangupsConversationsList")
QHangupsConversationsList.resize(250, 500)
self.centralwidget = QtWidgets.QWidget(QHangupsConversationsList)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.conversationsListWidget = QtWidgets.QListWidget(self.centralwidget)
self.conversationsListWidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.conversationsListWidget.setObjectName("conversationsListWidget")
self.verticalLayout.addWidget(self.conversationsListWidget)
QHangupsConversationsList.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(QHangupsConversationsList)
self.menubar.setGeometry(QtCore.QRect(0, 0, 250, 27))
self.menubar.setObjectName("menubar")
QHangupsConversationsList.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(QHangupsConversationsList)
self.statusbar.setObjectName("statusbar")
QHangupsConversationsList.setStatusBar(self.statusbar)
self.retranslateUi(QHangupsConversationsList)
QtCore.QMetaObject.connectSlotsByName(QHangupsConversationsList)
示例7: setupUi
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def setupUi(self, QHangupsConversations):
QHangupsConversations.setObjectName("QHangupsConversations")
QHangupsConversations.resize(500, 350)
self.centralwidget = QtWidgets.QWidget(QHangupsConversations)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.conversationsTabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.conversationsTabWidget.setElideMode(QtCore.Qt.ElideRight)
self.conversationsTabWidget.setTabsClosable(True)
self.conversationsTabWidget.setMovable(True)
self.conversationsTabWidget.setObjectName("conversationsTabWidget")
self.gridLayout.addWidget(self.conversationsTabWidget, 0, 0, 1, 1)
QHangupsConversations.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(QHangupsConversations)
self.menubar.setGeometry(QtCore.QRect(0, 0, 500, 27))
self.menubar.setObjectName("menubar")
QHangupsConversations.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(QHangupsConversations)
self.statusbar.setObjectName("statusbar")
QHangupsConversations.setStatusBar(self.statusbar)
self.retranslateUi(QHangupsConversations)
self.conversationsTabWidget.setCurrentIndex(-1)
QtCore.QMetaObject.connectSlotsByName(QHangupsConversations)
示例8: mousePressEvent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def mousePressEvent(self, event):
super(QGraphicsView, self).mousePressEvent(event)
#==============================================================================
# Zoom to rectangle, from
# https://wiki.python.org/moin/PyQt/Selecting%20a%20region%20of%20a%20widget
#==============================================================================
if event.button() == Qt.RightButton:
self._mousePressed = Qt.RightButton
self._rb_origin = QPoint(event.pos())
self.rubberBand.setGeometry(QRect(self._rb_origin, QSize()))
self.rubberBand.show()
#==============================================================================
# Mouse panning, taken from
# http://stackoverflow.com/a/15043279
#==============================================================================
elif event.button() == Qt.MidButton:
self._mousePressed = Qt.MidButton
self._mousePressedPos = event.pos()
self.setCursor(QtCore.Qt.ClosedHandCursor)
self._dragPos = event.pos()
示例9: mouseMoveEvent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def mouseMoveEvent(self, event):
super(QGraphicsView, self).mouseMoveEvent(event)
# # Useful debug
# try:
# self.debug_label.setText(str(itemsBoundingRect_nogrid().width()))
# except:
# print('Debug statement failed')
# Update the X,Y label indicating where the mouse is on the geometry
mouse_position = self.mapToScene(event.pos())
self.mouse_position = [mouse_position.x(), mouse_position.y()]
self.update_mouse_position_label()
if not self._rb_origin.isNull() and self._mousePressed == Qt.RightButton:
self.rubberBand.setGeometry(QRect(self._rb_origin, event.pos()).normalized())
# Middle-click-to-pan
if self._mousePressed == Qt.MidButton:
newPos = event.pos()
diff = newPos - self._dragPos
self._dragPos = newPos
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - diff.x())
self.verticalScrollBar().setValue(self.verticalScrollBar().value() - diff.y())
# event.accept()
示例10: mouseReleaseEvent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def mouseReleaseEvent(self, event):
if event.button() == Qt.RightButton:
self.rubberBand.hide()
rb_rect = QRect(self._rb_origin, event.pos())
rb_center = rb_rect.center()
rb_size = rb_rect.size()
if abs(rb_size.width()) > 3 and abs(rb_size.height()) > 3:
viewport_size = self.viewport().geometry().size()
zoom_factor_x = abs(viewport_size.width() / rb_size.width())
zoom_factor_y = abs(viewport_size.height() / rb_size.height())
new_center = self.mapToScene(rb_center)
zoom_factor = min(zoom_factor_x, zoom_factor_y)
self.zoom_view(zoom_factor)
self.centerOn(new_center)
self.update_grid()
if event.button() == Qt.MidButton:
self.setCursor(Qt.ArrowCursor)
self._mousePressed = None
self.update_grid()
示例11: getDetailInfo
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def getDetailInfo(self):
"""点击后进行动画效果的: 显示某歌曲的详细信息。"""
self.shortInfo.hide()
self.detailInfo.show()
self.showDetail = QPropertyAnimation(self, b"geometry")
x = self.pos().x()
y = self.pos().y()
self.showDetail.setStartValue(QRect(x, y, self.width(), self.height()))
# 获取顶层父窗口的长度。
self.showDetail.setEndValue(QRect(0, self.grandparent.header.height()+3, self.grandparent.width(), self.grandparent.mainContent.height()))
self.showDetail.setDuration(300)
self.showDetail.setEasingCurve(QEasingCurve.InBack)
self.showDetail.start(QAbstractAnimation.DeleteWhenStopped)
# 将该组件显示在最前,默认会嵌入到父组件里面。
self.raise_()
self.setDetailInfo()
示例12: getShortInfo
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def getShortInfo(self):
"""返回到原来的缩略图信息。"""
self.detailInfo.hide()
self.showShort = QPropertyAnimation(self, b"geometry")
x = self.pos().x()
y = self.pos().y()
self.showShort.setStartValue(QRect(0, self.grandparent.header.height(), self.grandparent.width(), self.grandparent.mainContent.height()))
self.showShort.setEndValue(QRect(0, self.grandparent.height()-64-self.parent.height(), self.grandparent.navigation.width(), 64))
self.showShort.setDuration(300)
self.showShort.setEasingCurve(QEasingCurve.InBack)
self.showShort.start(QAbstractAnimation.DeleteWhenStopped)
self.shortInfo.show()
self.raise_()
示例13: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._stream_buffer = QByteArray()
self._stream_buffer_start_index = -1
self._network_manager = None # type: QNetworkAccessManager
self._image_request = None # type: QNetworkRequest
self._image_reply = None # type: QNetworkReply
self._image = QImage()
self._image_rect = QRect()
self._source_url = QUrl()
self._started = False
self._mirror = False
self.setAntialiasing(True)
示例14: calculate_relative_position
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def calculate_relative_position(parent_rect: QtCore.QRect, own_size: QtCore.QSize,
constraint: RelativeLayoutConstraint):
"""
Calculates the position of the element, given its size, the position and size of the parent and a relative layout
constraint. The position is the position of the parent plus the weighted size of the parent, the weighted size of
the element and an offset. The weights and the offset are given by the constraint for each direction.
:param parent_rect: parent coordinates and size as rectangle
:param own_size: size of the element (width and height)
:param constraint: relative layout constraint to apply
:return: tuple of recommended x and y positions of the element
"""
"""
Returns the left, upper corner of an object if the parent rectangle (QRect) is given and our own size (QSize)
and a relative layout constraint (see RelativeLayoutConstraint).
"""
x = (parent_rect.x()
+ constraint.x[0] * parent_rect.width()
+ constraint.x[1] * own_size.width()
+ constraint.x[2])
y = (parent_rect.y()
+ constraint.y[0] * parent_rect.height()
+ constraint.y[1] * own_size.height()
+ constraint.y[2])
return x, y
示例15: setGeometry
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QRect [as 别名]
def setGeometry(self, rect: QtCore.QRect): # noqa: N802
"""
Layout the elements by calculating their relative position inside the parent, given the parents coordinates
and the sizes of the elements. The width and height are not changed but the offset is computed according to
the layout constraint and the parent size.
:param rect: Position and size of the parent.
"""
for item in self.items:
o_size = item.widget().size()
c = item.widget().layout_constraint
x, y = calculate_relative_position(rect, o_size, c)
item.setGeometry(QtCore.QRect(x, y, o_size.width(), o_size.height()))