本文整理汇总了Python中PySide2.QtCore类的典型用法代码示例。如果您正苦于以下问题:Python QtCore类的具体用法?Python QtCore怎么用?Python QtCore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QtCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
def paint(self, painter, option=None, widget=None):
if self.validateImage():
wasSmoothPixmapTransform = painter.testRenderHint(QtGui.QPainter.SmoothPixmapTransform)
painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
if Colors.noRescale:
# Let the painter scale the image for us. This may degrade
# both quality and performance.
if self.sharedImage.image is not None:
painter.drawImage(self.pos(), self.sharedImage.image)
else:
painter.drawPixmap(self.pos(), self.sharedImage.pixmap)
else:
m = painter.worldMatrix()
painter.setWorldMatrix(QtGui.QMatrix())
x = m.dx()
y = m.dy()
if self.noSubPixeling:
x = QtCore.qRound(x)
y = QtCore.qRound(y)
if self.sharedImage.image is not None:
painter.drawImage(QtCore.QPointF(x, y),
self.sharedImage.image)
else:
painter.drawPixmap(QtCore.QPointF(x, y),
self.sharedImage.pixmap)
if not wasSmoothPixmapTransform:
painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform,
False)
示例2: setRange
def setRange(self, minValue, maxValue):
if minValue < 0 or maxValue > 99 or minValue > maxValue:
QtCore.qWarning("LCDRange::setRange(%d, %d)\n"
"\tRange must be 0..99\n"
"\tand minValue must not be greater than maxValue" % (minValue, maxValue))
return
self.slider.setRange(minValue, maxValue)
示例3: drawBackgroundToPixmap
def drawBackgroundToPixmap(self):
r = self.scene.sceneRect()
self.background = QtGui.QPixmap(QtCore.qRound(r.width()),
QtCore.qRound(r.height()))
self.background.fill(QtCore.Qt.black)
painter = QtGui.QPainter(self.background)
bg = QtGui.QImage(':/images/demobg.png')
painter.drawImage(0, 0, bg)
示例4: __init__
def __init__(self):
super(ColorItem, self).__init__()
self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256,
QtCore.qrand() % 256)
self.setToolTip(
"QColor(%d, %d, %d)\nClick and drag this color onto the robot!" %
(self.color.red(), self.color.green(), self.color.blue())
)
self.setCursor(QtCore.Qt.OpenHandCursor)
示例5: mouseMoveEvent
def mouseMoveEvent(self, event):
if QtCore.QLineF(QtCore.QPointF(event.screenPos()), QtCore.QPointF(event.buttonDownScreenPos(QtCore.Qt.LeftButton))).length() < QtWidgets.QApplication.startDragDistance():
return
drag = QtGui.QDrag(event.widget())
mime = QtCore.QMimeData()
drag.setMimeData(mime)
ColorItem.n += 1
if ColorItem.n > 2 and QtCore.qrand() % 3 == 0:
image = QtGui.QImage(':/images/head.png')
mime.setImageData(image)
drag.setPixmap(QtGui.QPixmap.fromImage(image).scaled(30,40))
drag.setHotSpot(QtCore.QPoint(15, 30))
else:
mime.setColorData(self.color)
mime.setText("#%02x%02x%02x" % (self.color.red(), self.color.green(), self.color.blue()))
pixmap = QtGui.QPixmap(34, 34)
pixmap.fill(QtCore.Qt.white)
painter = QtGui.QPainter(pixmap)
painter.translate(15, 15)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
self.paint(painter, None, None)
painter.end()
pixmap.setMask(pixmap.createHeuristicMask())
drag.setPixmap(pixmap)
drag.setHotSpot(QtCore.QPoint(15, 20))
drag.exec_()
self.setCursor(QtCore.Qt.OpenHandCursor)
示例6: _pyside
def _pyside():
from PySide import (
QtGui,
QtCore,
QtNetwork,
QtXml,
QtHelp,
QtUiTools,
__version__
)
QtWidgets = QtGui
Qt.__binding__ = "PySide"
Qt.__qt_version__ = QtCore.qVersion()
Qt.__binding_version__ = __version__
QtCompat.load_ui = lambda fname: QtUiTools.QUiLoader().load(fname)
QtCompat.setSectionResizeMode = QtGui.QHeaderView.setResizeMode
QtCompat.translate = (
lambda context, sourceText, disambiguation, n:
QtCore.QCoreApplication.translate(context,
sourceText,
disambiguation,
QtCore.QCoreApplication.CodecForTr,
n))
return QtCore, QtGui, QtWidgets, QtNetwork, QtXml, QtHelp
示例7: shotRect
def shotRect(self):
gravity = 4.0
time = self.timerCount / 40.0
velocity = self.shootForce
radians = self.shootAngle * 3.14159265 / 180
velx = velocity * math.cos(radians)
vely = velocity * math.sin(radians)
x0 = (CannonField.barrelRect.right() + 5) * math.cos(radians)
y0 = (CannonField.barrelRect.right() + 5) * math.sin(radians)
x = x0 + velx * time
y = y0 + vely * time - 0.5 * gravity * time * time
result = QtCore.QRect(0, 0, 6, 6)
result.moveCenter(QtCore.QPoint(QtCore.qRound(x), self.height() - 1 - QtCore.qRound(y)))
return result
示例8: __init__
def __init__(self):
super(Mouse, self).__init__()
self.angle = 0.0
self.speed = 0.0
self.mouseEyeDirection = 0.0
self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256,
QtCore.qrand() % 256)
self.rotate(QtCore.qrand() % (360 * 16))
# In the C++ version of this example, this class is also derived from
# QObject in order to receive timer events. PyQt does not support
# deriving from more than one wrapped class so we just create an
# explicit timer instead.
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.timerEvent)
self.timer.start(1000 / 33)
示例9: mouseMoveEvent
def mouseMoveEvent(self, event):
if not self.barrelPressed:
return
pos = event.pos()
if pos.x() <= 0:
pos.setX(1)
if pos.y() >= self.height():
pos.setY(self.height() - 1)
rad = math.atan((float(self.rect().bottom()) - pos.y()) / pos.x())
self.setAngle(QtCore.qRound(rad * 180 / 3.14159265))
示例10: keyPressEvent
def keyPressEvent(self, event):
key = event.key()
if key == QtCore.Qt.Key_Up:
self.centerNode.moveBy(0, -20)
elif key == QtCore.Qt.Key_Down:
self.centerNode.moveBy(0, 20)
elif key == QtCore.Qt.Key_Left:
self.centerNode.moveBy(-20, 0)
elif key == QtCore.Qt.Key_Right:
self.centerNode.moveBy(20, 0)
elif key == QtCore.Qt.Key_Plus:
self.scaleView(1.2)
elif key == QtCore.Qt.Key_Minus:
self.scaleView(1 / 1.2)
elif key == QtCore.Qt.Key_Space or key == QtCore.Qt.Key_Enter:
for item in self.scene().items():
if isinstance(item, Node):
item.setPos(-150 + QtCore.qrand() % 300, -150 + QtCore.qrand() % 300)
else:
QtGui.QGraphicsView.keyPressEvent(self, event)
示例11: calculateForces
def calculateForces(self):
if not self.scene() or self.scene().mouseGrabberItem() is self:
self.newPos = self.pos()
return
# Sum up all forces pushing this item away.
xvel = 0.0
yvel = 0.0
for item in self.scene().items():
if not isinstance(item, Node):
continue
line = QtCore.QLineF(self.mapFromItem(item, 0, 0), QtCore.QPointF(0, 0))
dx = line.dx()
dy = line.dy()
l = 2.0 * (dx * dx + dy * dy)
if l > 0:
xvel += (dx * 150.0) / l
yvel += (dy * 150.0) / l
# Now subtract all forces pulling items together.
weight = (len(self.edgeList) + 1) * 10.0
for edge in self.edgeList:
if edge().sourceNode() is self:
pos = self.mapFromItem(edge().destNode(), 0, 0)
else:
pos = self.mapFromItem(edge().sourceNode(), 0, 0)
xvel += pos.x() / weight
yvel += pos.y() / weight
if QtCore.qAbs(xvel) < 0.1 and QtCore.qAbs(yvel) < 0.1:
xvel = yvel = 0.0
sceneRect = self.scene().sceneRect()
self.newPos = self.pos() + QtCore.QPointF(xvel, yvel)
self.newPos.setX(min(max(self.newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10))
self.newPos.setY(min(max(self.newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10))
示例12: timerEvent
def timerEvent(self):
# Don't move too far away.
lineToCenter = QtCore.QLineF(QtCore.QPointF(0, 0), self.mapFromScene(0, 0))
if lineToCenter.length() > 150:
angleToCenter = math.acos(lineToCenter.dx() / lineToCenter.length())
if lineToCenter.dy() < 0:
angleToCenter = Mouse.TwoPi - angleToCenter;
angleToCenter = Mouse.normalizeAngle((Mouse.Pi - angleToCenter) + Mouse.Pi / 2)
if angleToCenter < Mouse.Pi and angleToCenter > Mouse.Pi / 4:
# Rotate left.
self.angle += [-0.25, 0.25][self.angle < -Mouse.Pi / 2]
elif angleToCenter >= Mouse.Pi and angleToCenter < (Mouse.Pi + Mouse.Pi / 2 + Mouse.Pi / 4):
# Rotate right.
self.angle += [-0.25, 0.25][self.angle < Mouse.Pi / 2]
elif math.sin(self.angle) < 0:
self.angle += 0.25
elif math.sin(self.angle) > 0:
self.angle -= 0.25
# Try not to crash with any other mice.
dangerMice = self.scene().items(QtGui.QPolygonF([self.mapToScene(0, 0),
self.mapToScene(-30, -50),
self.mapToScene(30, -50)]))
for item in dangerMice:
if item is self:
continue
lineToMouse = QtCore.QLineF(QtCore.QPointF(0, 0), self.mapFromItem(item, 0, 0))
angleToMouse = math.acos(lineToMouse.dx() / lineToMouse.length())
if lineToMouse.dy() < 0:
angleToMouse = Mouse.TwoPi - angleToMouse
angleToMouse = Mouse.normalizeAngle((Mouse.Pi - angleToMouse) + Mouse.Pi / 2)
if angleToMouse >= 0 and angleToMouse < Mouse.Pi / 2:
# Rotate right.
self.angle += 0.5
elif angleToMouse <= Mouse.TwoPi and angleToMouse > (Mouse.TwoPi - Mouse.Pi / 2):
# Rotate left.
self.angle -= 0.5
# Add some random movement.
if len(dangerMice) > 1 and (QtCore.qrand() % 10) == 0:
if QtCore.qrand() % 1:
self.angle += (QtCore.qrand() % 100) / 500.0
else:
self.angle -= (QtCore.qrand() % 100) / 500.0
self.speed += (-50 + QtCore.qrand() % 100) / 100.0
dx = math.sin(self.angle) * 10
self.mouseEyeDirection = [dx / 5, 0.0][QtCore.qAbs(dx / 5) < 1]
self.rotate(dx)
self.setPos(self.mapToParent(0, -(3 + math.sin(self.speed) * 3)))
示例13: _pyside2
def _pyside2():
from PySide2 import (
QtWidgets,
QtGui,
QtCore,
QtNetwork,
QtXml,
QtHelp,
QtUiTools,
__version__
)
Qt.__binding__ = "PySide2"
Qt.__qt_version__ = QtCore.qVersion()
Qt.__binding_version__ = __version__
QtCompat.load_ui = lambda fname: QtUiTools.QUiLoader().load(fname)
QtCompat.setSectionResizeMode = QtWidgets.QHeaderView.setSectionResizeMode
QtCompat.translate = QtCore.QCoreApplication.translate
return QtCore, QtGui, QtWidgets, QtNetwork, QtXml, QtHelp
示例14: enumerate
# Values.
for i, item in enumerate(items):
# Ellipse.
ellipseState.assignProperty(item, 'pos',
QtCore.QPointF(math.cos((i / 63.0) * 6.28) * 250,
math.sin((i / 63.0) * 6.28) * 250))
# Figure 8.
figure8State.assignProperty(item, 'pos',
QtCore.QPointF(math.sin((i / 63.0) * 6.28) * 250,
math.sin(((i * 2)/63.0) * 6.28) * 250))
# Random.
randomState.assignProperty(item, 'pos',
QtCore.QPointF(-250 + QtCore.qrand() % 500,
-250 + QtCore.qrand() % 500))
# Tiled.
tiledState.assignProperty(item, 'pos',
QtCore.QPointF(((i % 8) - 4) * kineticPix.width() + kineticPix.width() / 2,
((i // 8) - 4) * kineticPix.height() + kineticPix.height() / 2))
# Centered.
centeredState.assignProperty(item, 'pos', QtCore.QPointF())
# Ui.
view = View(scene)
view.setWindowTitle("Animated Tiles")
view.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate)
view.setBackgroundBrush(QtGui.QBrush(bgPix))
示例15: range
dx = math.sin(self.angle) * 10
self.mouseEyeDirection = [dx / 5, 0.0][QtCore.qAbs(dx / 5) < 1]
self.rotate(dx)
self.setPos(self.mapToParent(0, -(3 + math.sin(self.speed) * 3)))
if __name__ == '__main__':
import sys
MouseCount = 7
app = QtGui.QApplication(sys.argv)
QtCore.qsrand(QtCore.QTime(0,0,0).secsTo(QtCore.QTime.currentTime()))
scene = QtGui.QGraphicsScene()
scene.setSceneRect(-300, -300, 600, 600)
scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
for i in range(MouseCount):
mouse = Mouse()
mouse.setPos(math.sin((i * 6.28) / MouseCount) * 200,
math.cos((i * 6.28) / MouseCount) * 200)
scene.addItem(mouse)
view = QtGui.QGraphicsView(scene)
view.setRenderHint(QtGui.QPainter.Antialiasing)
view.setBackgroundBrush(QtGui.QBrush(QtGui.QPixmap(':/images/cheese.jpg')))
view.setCacheMode(QtGui.QGraphicsView.CacheBackground)