Python PyQt5.QtCore.QSizeF() Examples

The following are 16 code examples of PyQt5.QtCore.QSizeF(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .
Example #1
Source File: PrinterPyQt5.py    From photobooth with GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, page_size, print_pdf=False):

        super().__init__(page_size)

        self._printer = QPrinter(QPrinter.HighResolution)
        self._printer.setFullPage(True)
        self._printer.setPageSize(QtGui.QPageSize(QtCore.QSizeF(*page_size),
                                                  QtGui.QPageSize.Millimeter))
        self._printer.setColorMode(QPrinter.Color)

        logging.info('Using printer "%s"', self._printer.printerName())

        self._print_pdf = print_pdf
        if self._print_pdf:
            logging.info('Using PDF printer')
            self._counter = 0
            self._printer.setOutputFormat(QPrinter.PdfFormat) 
Example #2
Source File: webkittab.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def _on_contents_size_changed(self, size):
        self.contents_size_changed.emit(QSizeF(size)) 
Example #3
Source File: breathing_dlg.py    From mindfulness-at-the-computer with GNU General Public License v3.0 5 votes vote down vote up
def _breathing_gi_hover(self):
        if mc.mc_global.breathing_state == mc.mc_global.BreathingState.breathing_in:
            return

        hover_rectangle_qsize = QtCore.QSizeF(BR_WIDTH_FT, BR_HEIGHT_FT)
        # noinspection PyCallByClass
        pos_pointf = QtWidgets.QGraphicsItem.mapFromItem(
            self._breathing_gi,
            self._breathing_gi,
            self._breathing_gi.x() + (self._breathing_gi.boundingRect().width() - hover_rectangle_qsize.width()) / 2,
            self._breathing_gi.y() + (self._breathing_gi.boundingRect().height() - hover_rectangle_qsize.height()) / 2
        )
        # -widget coords
        hover_rectangle_coords_qrect = QtCore.QRectF(pos_pointf, hover_rectangle_qsize)

        cursor = QtGui.QCursor()  # -screen coords
        cursor_pos_widget_coords_qp = self.mapFromGlobal(cursor.pos())  # -widget coords

        logging.debug("cursor.pos() = " + str(cursor.pos()))
        logging.debug("cursor_pos_widget_coords_qp = " + str(cursor_pos_widget_coords_qp))
        logging.debug("hover_rectangle_coords_qrect = " + str(hover_rectangle_coords_qrect))

        if hover_rectangle_coords_qrect.contains(cursor_pos_widget_coords_qp):
            mc.mc_global.breathing_state = mc.mc_global.BreathingState.breathing_in
            self.ib_signal.emit()
            self.text_gi.update_pos_and_origin_point(VIEW_WIDTH_INT, VIEW_HEIGHT_INT)
            self._breathing_gi.update_pos_and_origin_point(VIEW_WIDTH_INT, VIEW_HEIGHT_INT) 
Example #4
Source File: contentwidgets.py    From Lector with GNU General Public License v3.0 5 votes vote down vote up
def create_pages(self, text_mode=None):
        # Return to this value after page calcuation is done
        cursorTop = self.cursorForPosition(QtCore.QPoint(0, 0))

        # No changes in mode
        # if text_mode == self.text_mode:
        #     return

        # Account for resizeEvent
        if not text_mode:
            if self.text_mode == 'flow':
                return
            text_mode = self.text_mode

        # Single Page mode
        page_width = self.viewport().size().width()
        page_height = self.viewport().size().height()

        # Flow mode
        if text_mode == 'flow':
            page_height = -1

        # TODO
        # See what's an appropriate value to pad the text with
        # profile_index = self.bookToolBar.profileBox.currentIndex()
        # current_profile = self.bookToolBar.profileBox.itemData(
        #     profile_index, QtCore.Qt.UserRole)
        # padding = 20
        # Double page mode
        if text_mode == 'doublePage':
            page_width = page_width // 2 - 10

        self.text_mode = text_mode

        self.document().setPageSize(
            QtCore.QSizeF(page_width, page_height))

        self.generate_page_positions()
        self.set_page(cursorTop) 
Example #5
Source File: quickplotter.py    From phidl with MIT License 5 votes vote down vote up
def reset_view(self):
        # The SceneRect controls how far you can pan, make it larger than
        # just the bounding box so middle-click panning works
        panning_rect = QRectF(self.scene_bounding_rect)
        panning_rect_center = panning_rect.center()
        panning_rect_size = max(panning_rect.width(), panning_rect.height())*3
        panning_rect.setSize(QSizeF(panning_rect_size, panning_rect_size))
        panning_rect.moveCenter(panning_rect_center)
        self.setSceneRect(panning_rect)
        self.fitInView(self.scene_bounding_rect, Qt.KeepAspectRatio)
        self.zoom_view(0.8)

        self.update_grid() 
Example #6
Source File: Theme.py    From Uranium with GNU Lesser General Public License v3.0 5 votes vote down vote up
def getSize(self, size) -> QSizeF:
        if size in self._sizes:
            return self._sizes[size]

        Logger.log("w", "No size %s defined in Theme", size)
        return QSizeF() 
Example #7
Source File: Theme.py    From Uranium with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _initializeDefaults(self) -> None:
        self._fonts = {
            "system": QCoreApplication.instance().font(),
            "fixed": QFontDatabase.systemFont(QFontDatabase.FixedFont)
        }

        palette = QCoreApplication.instance().palette()
        self._colors = {
            "system_window": palette.window(),
            "system_text": palette.text()
        }

        self._sizes = {
            "line": QSizeF(self._em_width, self._em_height)
        } 
Example #8
Source File: TestTheme.py    From Uranium with GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_getKnownSize(theme):
    assert theme.getSize("test_size") == QSizeF(42, 1337) 
Example #9
Source File: TestTheme.py    From Uranium with GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_getUnknownSize(theme):
    assert theme.getSize("Dunno?") == QSizeF() 
Example #10
Source File: stamp.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def calculateTextSize(text):
        """
        Calculates the size of text. Crops to 96 pixels wide.
        """
        fontMetrics = QtGui.QFontMetrics(QtGui.QFont())
        fontRect = fontMetrics.boundingRect(QtCore.QRect(0, 0, 96, 48), Qt.TextWordWrap, text)
        w, h = fontRect.width(), fontRect.height()
        return QtCore.QSizeF(min(w, 96), h) 
Example #11
Source File: ORStoolsDialog.py    From orstools-qgis-plugin with MIT License 5 votes vote down vote up
def _linetool_annotate_point(self, point, idx):
        annotation = QgsTextAnnotation()

        c = QTextDocument()
        html = "<strong>" + str(idx) + "</strong>"
        c.setHtml(html)

        annotation.setDocument(c)

        annotation.setFrameSize(QSizeF(27, 20))
        annotation.setFrameOffsetFromReferencePoint(QPointF(5, 5))
        annotation.setMapPosition(point)
        annotation.setMapPositionCrs(self.map_crs)

        return QgsMapCanvasAnnotationItem(annotation, self._iface.mapCanvas()).annotation() 
Example #12
Source File: pdf.py    From eddy with GNU General Public License v3.0 5 votes vote down vote up
def run(self, path):
        """
        Perform PDF document generation.
        :type path: str
        """
        shape = self.diagram.visibleRect(margin=20)
        if shape:
            LOGGER.info('Exporting diagram %s to %s', self.diagram.name, path)
            printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution)
            printer.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat)
            printer.setOutputFileName(path)
            printer.setPaperSize(QtPrintSupport.QPrinter.Custom)
            printer.setPageSize(QtGui.QPageSize(QtCore.QSizeF(shape.width(), shape.height()), QtGui.QPageSize.Point))
            painter = QtGui.QPainter()
            if painter.begin(printer):
                # TURN CACHING OFF
                for item in self.diagram.items():
                    if item.isNode() or item.isEdge():
                        item.setCacheMode(AbstractItem.NoCache)
                # RENDER THE DIAGRAM IN THE PAINTER
                self.diagram.render(painter, source=shape)
                # TURN CACHING ON
                for item in self.diagram.items():
                    if item.isNode() or item.isEdge():
                        item.setCacheMode(AbstractItem.DeviceCoordinateCache)
                # COMPLETE THE EXPORT
                painter.end()
                # OPEN THE DOCUMENT
                openPath(path) 
Example #13
Source File: pyqt_backend.py    From ezdxf with MIT License 5 votes vote down vote up
def boundingRect(self) -> qc.QRectF:
        return qc.QRectF(self.pos, qc.QSizeF(1, 1)) 
Example #14
Source File: invoice_maker_printable.py    From Mastering-GUI-Programming-with-Python with MIT License 5 votes vote down vote up
def set_page_size(self, qrect):
        self.doc_width = qrect.width()
        self.doc_height = qrect.height()
        self.setFixedSize(qtc.QSize(self.doc_width, self.doc_height))
        self.document().setPageSize(
            qtc.QSizeF(self.doc_width, self.doc_height)) 
Example #15
Source File: ocrwidget.py    From lector with GNU General Public License v2.0 5 votes vote down vote up
def mousePressEvent(self, event):
        # grabbing the position of the widget
        sp = self.mapToScene(event.pos())
        ret = self.scene().areaAt(sp)

        edge = ret % 100
        iArea = int(ret / 100) - 1

        # resizing/moving the area if it exists
        if edge:
            self.bResizing = True
            self.resizingEdge = edge
            self.resizingArea = self.scene().areas[iArea]
            self.resizingStartingPos = sp
            self.resizingAreaRect = self.resizingArea.rect()
            self.resizingAreaPos = self.resizingArea.pos()
            self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False)
        # creation of a new area if there is an image
        elif iArea == -1 and self.filename:
            size = QSizeF(0, 0)
            newArea = self.scene().createArea(sp,
                size, self.areaType, self.areaBorder,
                self.areaTextSize)

            self.bResizing = True
            self.resizingEdge = 10
            self.resizingArea = newArea
            self.resizingStartingPos = sp
            self.resizingAreaRect = self.resizingArea.rect()
            self.resizingAreaPos = self.resizingArea.pos()
            self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False)

        QGraphicsView.mousePressEvent(self, event) 
Example #16
Source File: LabeledArrow.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
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)