本文整理汇总了Python中PySide2.QtCore.QRect方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QRect方法的具体用法?Python QtCore.QRect怎么用?Python QtCore.QRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide2.QtCore
的用法示例。
在下文中一共展示了QtCore.QRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sampleLatentAtPos
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def sampleLatentAtPos(self, pos):
imgRect = self.getImageDims()
gridDims = self.gridSize #self.latentSize *
w = int(imgRect.width() / self.gridSize.width()) #self.latentSize * ( #self.getCurrentLatentWidth()
h_l = self.latentSize // 2
self.sampledLatentPos = self.getGridCoords(pos)
posGrid = self.sampledLatentPos - QPoint(h_l, h_l)
posGrid.setX(min(max(posGrid.x(), 0), gridDims.width() - h_l))
posGrid.setY(min(max(posGrid.y(), 0), gridDims.height() - h_l))
posImg = QPoint(int(imgRect.width() * posGrid.x() / gridDims.width()), int(imgRect.height() * posGrid.y() / gridDims.height()))
fullImg = self._image.pixmap()
imgRegion = fullImg.copy(QRect(posImg, QSize(w, w))).toImage()
region_array = np.ndarray(shape=(imgRegion.height(), imgRegion.width(), 4), dtype=np.uint8, buffer=imgRegion.bits())
self.sampledLatent = region_array[:, :, [2, 1, 0]] #BGR -> RGB
示例2: test_level
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def test_level(level_info, qtbot):
*level_info, transparent = level_info
level_ref = LevelRef()
level_ref.load_level(*level_info)
Block._block_cache.clear()
# monkeypatch level names, since the level name data is broken atm
level_ref.level.name = current_test_name()
level_view = LevelView(None, level_ref, ContextMenu(level_ref))
level_view.transparency = transparent
level_view.draw_jumps = False
level_view.draw_grid = False
level_view.draw_autoscroll = True
rect = QRect(QPoint(0, 0), QSize(*level_ref.level.size) * 16)
level_view.setGeometry(rect)
_test_level_against_reference(level_view, qtbot)
示例3: _set_window_geometry
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def _set_window_geometry(self):
"""
Loads stored window geometry preferences and applies them to the QWindow.
.setGeometry() sets the size of the window minus the window frame.
For this reason it should be set on self.blender_widget.
"""
settings = QSettings('Tech-Artists.org', 'Blender Qt Wrapper')
settings.beginGroup(self._settings_key_window_group_name)
if settings.value(self._settings_key_full_screen, 'false').lower() == 'true':
self.blender_widget.showFullScreen()
return
if settings.value(self._settings_key_maximized, 'false').lower() == 'true':
self.blender_widget.showMaximized()
return
self.blender_widget.setGeometry(settings.value(self._settings_key_geometry, QRect(0, 0, 640, 480)))
self.blender_widget.show()
settings.endGroup()
return
示例4: _create_major_item_boxes
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def _create_major_item_boxes(self, item_database: ItemDatabase):
for major_item in item_database.major_items.values():
if major_item.required or major_item.item_category == ItemCategory.ENERGY_TANK:
continue
category_box, category_layout, elements = self._boxes_for_category[major_item.item_category]
item_button = QToolButton(category_box)
item_button.setGeometry(QRect(20, 30, 24, 21))
item_button.setText("...")
item_label = QLabel(category_box)
item_label.setText(major_item.name)
i = len(elements)
category_layout.addWidget(item_button, i, 0)
category_layout.addWidget(item_label, i, 1)
elements[major_item] = item_button, item_label
item_button.clicked.connect(partial(self.show_item_popup, major_item))
示例5: show_instruction
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def show_instruction(self, insn_addr, insn_pos=None, centering=False, use_block_pos=False):
block = self._insaddr_to_block.get(insn_addr, None) # type: QGraphBlock
if block is not None:
if use_block_pos:
x, y = block.mapToScene(block.x(), block.y())
else:
pos = block.mapToScene(*block.instruction_position(insn_addr))
x, y = pos.x(), pos.y()
if not centering:
# is it visible?
viewport = self.viewport()
visible_area = self.mapToScene(QRect(0, 0, viewport.width(), viewport.height())).boundingRect()
topx = visible_area.x()
topy = visible_area.y()
if topx <= x < topx + visible_area.width() and topy <= y < topy + visible_area.height():
return
# make it visible in the center
self.centerOn(x, y)
示例6: show_instruction
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def show_instruction(self, insn_addr, insn_pos=None, centering=False, use_block_pos=False):
"""
:param insn_addr:
:param QGraphicsItem item:
:param centering:
:param use_block_pos:
:return:
"""
if insn_pos is not None:
# check if item is already visible in the viewport
viewport = self._viewer.viewport()
rect = self._viewer.mapToScene(QRect(0, 0, viewport.width(), viewport.height())).boundingRect()
if rect.contains(insn_pos):
return
self.navigate_to_addr(insn_addr)
示例7: __init__
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def __init__(self, parent=None):
super(SlippyMap, self).__init__(parent)
self._offset = QPoint()
self._tilesRect = QRect()
self._tilePixmaps = {} # Point(x, y) to QPixmap mapping
self._manager = QNetworkAccessManager()
self._url = QUrl()
# public vars
self.width = 400
self.height = 300
self.zoom = 15
self.latitude = 59.9138204
self.longitude = 10.7387413
self._emptyTile = QPixmap(TDIM, TDIM)
self._emptyTile.fill(Qt.lightGray)
self.request = QNetworkRequest()
self.cache = QNetworkDiskCache()
self.cache.setCacheDirectory(QStandardPaths.writableLocation(QStandardPaths.CacheLocation))
self._manager.setCache(self.cache)
self._manager.finished.connect(self.handleNetworkData)
示例8: __init__
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def __init__(self, parent=None):
super(ColorWheel, self).__init__(parent)
self._is_clicked = False
self._rect = QtCore.QRect(25, 25, 50, 50)
self._current_color = QtGui.QColor(WHITE)
self._color_point = QtCore.QPoint(150, 50)
self._current_tool = None
self._angle = 180
self.setFixedSize(100, 100)
self.initUI()
示例9: synchronize_image
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def synchronize_image(self):
self.pixmap = QtGui.QPixmap(self.options['image.path'])
if self.options['image.fit'] is True:
self.image_rect = None
return
self.image_rect = QtCore.QRect(
self.rect.left(),
self.rect.top(),
self.options['image.width'],
self.options['image.height'])
self.image_rect.moveCenter(self.rect.center().toPoint())
示例10: proportional_rect
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def proportional_rect(rect, percent=None):
""" return a scaled rect with a percentage """
factor = float(percent) / 100
width = rect.width() * factor
height = rect.height() * factor
left = rect.left() + round((rect.width() - width) / 2)
top = rect.top() + round((rect.height() - height) / 2)
return QtCore.QRect(left, top, width, height)
示例11: mousePressEvent
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def mousePressEvent(self, event):
"""Re-implement QGraphicsView's mousePressEvent handler"""
# status of CTRL key
ctrl = event.modifiers() == QtCore.Qt.ControlModifier
# if a mouse event happens in the graphics view
# put the keyboard focus to the view as well
self.setFocus()
self.origin = event.pos()
# do rubberband zoom only with left mouse button
if event.button() == QtCore.Qt.LeftButton:
self._leftMousePressed = True
self._dragPos = event.pos()
if ctrl:
self.setCursor(QtCore.Qt.ClosedHandCursor)
else:
# initiate rubberband origin and size (zero at first)
self.rubberband.setGeometry(QtCore.QRect(self.origin,
QtCore.QSize()))
# show, even at zero size
# allows to check later using isVisible()
self.rubberband.show()
# call corresponding base class method
super().mousePressEvent(event)
示例12: mouseMoveEvent
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def mouseMoveEvent(self, event):
"""Re-implement QGraphicsView's mouseMoveEvent handler"""
# if a mouse event happens in the graphics view
# put the keyboard focus to the view as well
self.setFocus()
# status of CTRL key
ctrl = event.modifiers() == QtCore.Qt.ControlModifier
# pan the view with the left mouse button and CRTL down
if self._leftMousePressed and ctrl:
self.setCursor(QtCore.Qt.ClosedHandCursor)
newPos = event.pos()
diff = newPos - self._dragPos
self._dragPos = newPos
# this actually does the pan
# no matter if scroll bars are displayed or not
self.horizontalScrollBar().setValue(
self.horizontalScrollBar().value() - diff.x())
self.verticalScrollBar().setValue(
self.verticalScrollBar().value() - diff.y())
if self.rubberband.isVisible() and not ctrl:
self.setInteractive(False)
self.rubberband.setGeometry(
QtCore.QRect(self.origin, event.pos()).normalized())
# call corresponding base class method
super().mouseMoveEvent(event)
示例13: adjustMarkerSize
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def adjustMarkerSize(self):
"""Adjust marker size during zoom. Marker items are circles
which are otherwise affected by zoom. Using MARKERSIZE from
Settings a fixed markersize (e.g. 3 pixels) can be kept.
This method immitates the behaviour of pen.setCosmetic()
"""
if not self.parent.airfoil:
return
# markers are drawn in GraphicsItem using scene coordinates
# in order to keep them constant size, also when zooming
# a fixed pixel size (MARKERSIZE from settings) is mapped to
# scene coordinates
# depending on the zoom, this leads to always different
# scene coordinates
# map a square with side length of MARKERSIZE to the scene coords
mappedMarker = self.mapToScene(
QtCore.QRect(0, 0, MARKERSIZE, MARKERSIZE))
mappedMarkerWidth = mappedMarker.boundingRect().width()
if self.parent.airfoil.contourPolygon:
markers = self.parent.airfoil.polygonMarkers
x, y = self.parent.airfoil.raw_coordinates
for i, marker in enumerate(markers):
# in case of circle, args is a QRectF
marker.args = [QtCore.QRectF(x[i] - mappedMarkerWidth,
y[i] - mappedMarkerWidth,
2. * mappedMarkerWidth,
2. * mappedMarkerWidth)]
# if self.parent.airfoil.contourSpline:
if hasattr(self.parent.airfoil, 'contourSpline'):
markers = self.parent.airfoil.splineMarkers
x, y = self.parent.airfoil.spline_data[0]
for i, marker in enumerate(markers):
# in case of circle, args is a QRectF
marker.args = [QtCore.QRectF(x[i] - mappedMarkerWidth,
y[i] - mappedMarkerWidth,
2. * mappedMarkerWidth,
2. * mappedMarkerWidth)]
示例14: get_rect
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def get_rect(self, block_length: int = 1):
width, height = self.size
return QRect(QPoint(0, 0), QSize(width, height) * block_length)
示例15: numberbarPaint
# 需要导入模块: from PySide2 import QtCore [as 别名]
# 或者: from PySide2.QtCore import QRect [as 别名]
def numberbarPaint(self, number_bar, event):
font_metrics = self.fontMetrics()
current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
block = self.firstVisibleBlock()
line_count = block.blockNumber()
painter = QtGui.QPainter(number_bar)
painter.fillRect(event.rect(), self.palette().base())
# Iterate over all visible text blocks in the document.
while block.isValid():
line_count += 1
block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
# Check if the position of the block is out side of the visible
# area.
if not block.isVisible() or block_top >= event.rect().bottom():
break
# We want the line number for the selected line to be bold.
if line_count == current_line:
font = painter.font()
font.setBold(True)
painter.setFont(font)
else:
font = painter.font()
font.setBold(False)
painter.setFont(font)
# Draw the line number right justified at the position of the line.
paint_rect = QtCore.QRect(0, block_top, number_bar.width(), font_metrics.height())
painter.drawText(paint_rect, QtCore.Qt.AlignRight, unicode(line_count))
block = block.next()
painter.end()