我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用PyQt5.QtCore.QSizeF()。
def boundingRect(self): """ Override inherited function to enlarge selection of Arrow to include all @param flag: The flag to enable or disable Selection """ if not self.sc: # since this function is called before paint; and scale is unknown return QtCore.QRectF(self.startp.x(), self.startp.y(), 1e-9, 1e-9) arrowSize = self.arrowSize / self.sc extra = arrowSize # self.pen.width() + if self.endp is None: dx = cos(self.angle) * self.length / self.sc dy = sin(self.angle) * self.length / self.sc endp = QtCore.QPointF(self.startp.x() - dx, self.startp.y() + dy) else: endp = QtCore.QPointF(self.endp.x, -self.endp.y) brect = QtCore.QRectF(self.startp, QtCore.QSizeF(endp.x()-self.startp.x(), endp.y()-self.startp.y())).normalized().adjusted(-extra, -extra, extra, extra) return brect
def openFile(self, fileName): if fileName != '' or fileName is not None: self.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(fileName))) # set resolution res_orig = get_video_resolution(fileName) self.aspect_ratio = float(res_orig[0]) / res_orig[1] self.videoItem.setSize(QSizeF(WIDTH, WIDTH / self.aspect_ratio)) self.setFixedHeight(WIDTH / self.aspect_ratio + 2*WIGGLE) self.playButton.setEnabled(True) # trick to show screenshot of the first frame of video self.mediaPlayer.play() self.mediaPlayer.pause()
def textSize(self): return QtCore.QSizeF( self.__textItem.textWidth(), self.__font.pointSizeF() )
def __init__(self, port, graph, hOffset, color, connectionPointType): super(PortCircle, self).__init__(port) self.__port = port self._graph = graph self._connectionPointType = connectionPointType self.__connections = set() self._supportsOnlySingleConnections = connectionPointType == 'In' self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)) size = QtCore.QSizeF(self.__diameter, self.__diameter) self.setPreferredSize(size) self.setWindowFrameMargins(0, 0, 0, 0) self.transform().translate(self.__radius * hOffset, 0) self.__defaultPen = QtGui.QPen(QtGui.QColor("#000000"), 1.0) self.__hoverPen = QtGui.QPen(QtGui.QColor("#000000"), 1.5) self._ellipseItem = QtWidgets.QGraphicsEllipseItem(self) self._ellipseItem.setPen(self.__defaultPen) self._ellipseItem.setPos(size.width()/2, size.height()/2) self._ellipseItem.setRect( -self.__radius, -self.__radius, self.__diameter, self.__diameter, ) self.setColor(color) self.setAcceptHoverEvents(True)
def textSize(self): return QtCore.QSizeF( self.__textItem.textWidth(), self.__font.pointSizeF() + self.__labelBottomSpacing ) # def paint(self, painter, option, widget): # super(NodeTitle, self).paint(painter, option, widget) # painter.setPen(QtGui.QPen(QtGui.QColor(0, 255, 0))) # painter.drawRect(self.windowFrameRect())
def run(self): app = QApplication.instance() if app is None: app = QApplication(['--platform', 'minimal']) # we need this call to correctly render images... app.processEvents() printer = QPrinter() if self.printer_name: printer.setPrinterName(self.printer_name) printer.setResolution(96) text_document = QTextDocument() printer.setFullPage(True) printer.setPageMargins(5, 5, 5, 5, QPrinter.Millimeter) page_size = QSizeF() page_size.setHeight(printer.height()) page_size.setWidth(printer.width()) text_document.setPageSize(page_size) text_document.setDocumentMargin(0.0) text_document.setHtml(self.html) text_document.print_(printer)
def resizeEvent(self, event): self.scene().setSceneRect(0, 0, event.size().width(), event.size().height()) self.player.setSize(QSizeF(event.size().width(), event.size().height())) self.bar.setGeometry(0, event.size().height()-self.bar.height(), event.size().width(), self.bar.height()) self.subtitleitem.setPos(QPointF((event.size().width()-self.subtitleitem.document().size().width())/2, event.size().height() - 150)) self.cc_dialog.setGeometry(event.size().width() - self.cc_dialog.width() - 30, event.size().height() - self.cc_dialog.height() - ( 20 + self.bar.height()), self.cc_dialog.width(), self.cc_dialog.height())
def intrinsicSize(self, doc, posInDocument, format): renderer = QSvgRenderer(format.property(Window.SvgData)) size = renderer.defaultSize() if size.height() > 25: size *= 25.0 / size.height() return QSizeF(size)
def boundingRect(self): extra = (self.pen().width() + 20) / 2.0 try: return QRectF(self.line().p1(), QSizeF(self.line().p2().x() - self.line().p1().x(), self.line().p2().y() - self.line().p1().y())) \ .normalized().adjusted(-extra, -extra, extra, extra) except RuntimeError: return QRectF(0,0,0,0)
def __init__(self, parent=None): super(VideoPlayer, self).__init__(parent) self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.videoItem = QGraphicsVideoItem() self.videoItem.setSize(QSizeF(640, 480)) scene = QGraphicsScene(self) graphicsView = QGraphicsView(scene) scene.addItem(self.videoItem) rotateSlider = QSlider(Qt.Horizontal) rotateSlider.setRange(-180, 180) rotateSlider.setValue(0) rotateSlider.valueChanged.connect(self.rotateVideo) openButton = QPushButton("Open...") openButton.clicked.connect(self.openFile) self.playButton = QPushButton() self.playButton.setEnabled(False) self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playButton.clicked.connect(self.play) self.positionSlider = QSlider(Qt.Horizontal) self.positionSlider.setRange(0, 0) self.positionSlider.sliderMoved.connect(self.setPosition) controlLayout = QHBoxLayout() controlLayout.setContentsMargins(0, 0, 0, 0) controlLayout.addWidget(openButton) controlLayout.addWidget(self.playButton) controlLayout.addWidget(self.positionSlider) layout = QVBoxLayout() layout.addWidget(graphicsView) layout.addWidget(rotateSlider) layout.addLayout(controlLayout) self.setLayout(layout) self.mediaPlayer.setVideoOutput(self.videoItem) self.mediaPlayer.stateChanged.connect(self.mediaStateChanged) self.mediaPlayer.positionChanged.connect(self.positionChanged) self.mediaPlayer.durationChanged.connect(self.durationChanged)