Python PyQt5.QtGui.QRegion() Examples

The following are 7 code examples for showing how to use PyQt5.QtGui.QRegion(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .

Example 1
Project: Lector   Author: BasioMeusPuga   File: definitionsdialog.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super(DefinitionsUI, self).__init__()
        self.setupUi(self)
        self._translate = QtCore.QCoreApplication.translate

        self.parent = parent
        self.previous_position = None

        self.setWindowFlags(
            QtCore.Qt.Popup |
            QtCore.Qt.FramelessWindowHint)

        radius = 15
        path = QtGui.QPainterPath()
        path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)

        try:
            mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
            self.setMask(mask)
        except TypeError:  # Required for older versions of Qt
            pass

        self.definitionView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        self.app_id = 'bb7a91f9'
        self.app_key = 'fefacdf6775c347b52e9efa2efe642ef'

        self.root_url = 'https://od-api.oxforddictionaries.com:443/api/v1/inflections/'
        self.define_url = 'https://od-api.oxforddictionaries.com:443/api/v1/entries/'

        self.pronunciation_mp3 = None

        self.okButton.clicked.connect(self.hide)
        self.dialogBackground.clicked.connect(self.color_background)
        if multimedia_available:
            self.pronounceButton.clicked.connect(self.play_pronunciation)
        else:
            self.pronounceButton.setEnabled(False) 
Example 2
Project: Lector   Author: BasioMeusPuga   File: metadatadialog.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super(MetadataUI, self).__init__()
        self.setupUi(self)
        self._translate = QtCore.QCoreApplication.translate

        self.setWindowFlags(
            QtCore.Qt.Popup |
            QtCore.Qt.FramelessWindowHint)

        self.parent = parent

        radius = 15
        path = QtGui.QPainterPath()
        path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)

        try:
            mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
            self.setMask(mask)
        except TypeError:  # Required for older versions of Qt
            pass

        self.parent = parent
        self.database_path = self.parent.database_path

        self.book_index = None
        self.book_year = None
        self.previous_position = None
        self.cover_for_database = None

        self.coverView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.coverView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        self.okButton.clicked.connect(self.ok_pressed)
        self.cancelButton.clicked.connect(self.cancel_pressed)
        self.dialogBackground.clicked.connect(self.color_background)

        self.titleLine.returnPressed.connect(self.ok_pressed)
        self.authorLine.returnPressed.connect(self.ok_pressed)
        self.yearLine.returnPressed.connect(self.ok_pressed)
        self.tagsLine.returnPressed.connect(self.ok_pressed) 
Example 3
Project: Lector   Author: BasioMeusPuga   File: dockwidgets.py    License: GNU General Public License v3.0 5 votes vote down vote up
def showEvent(self, event=None):
        # TODO
        # See what happens when the size of the viewport is smaller
        # than the size of the dock

        viewport_bottomRight = self.contentView.mapToGlobal(
            self.contentView.viewport().rect().bottomRight())

        # Dock dimensions
        desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
        dock_width = desktop_size.width() // 4.5
        dock_height = 30

        dock_x = viewport_bottomRight.x() - dock_width - 30
        dock_y = viewport_bottomRight.y() - 70

        self.main_window.active_docks.append(self)
        self.setGeometry(dock_x, dock_y, dock_width, dock_height)

        # Rounded
        radius = 20
        path = QtGui.QPainterPath()
        path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)
        try:
            mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
            self.setMask(mask)
        except TypeError:  # Required for older versions of Qt
            pass

        self.animation.start() 
Example 4
Project: detection   Author: xsyann   File: detection.py    License: GNU General Public License v2.0 5 votes vote down vote up
def fillImage(self, pixmap, painter, roi, param, source):
        """Draw image in roi.
        """
        x, y, w, h = roi
        fillPixmap = QPixmap(param.fillPath)
        if not fillPixmap.isNull():
            fillPixmap = fillPixmap.scaled(w, h, QtCore.Qt.IgnoreAspectRatio)
            mask = self.getMask(pixmap, x, y, w, h, param.shape, None,
                                QtCore.Qt.white, QtCore.Qt.black)
            painter.setClipRegion(QtGui.QRegion(QtGui.QBitmap(mask)))
            painter.drawPixmap(x, y, fillPixmap)
            painter.setClipping(False) 
Example 5
Project: QMusic   Author: dragondjf   File: dquickview.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
def setRoundMask(self):
        bmp = QPixmap(self.size())
        bmp.fill(Qt.white)
        p = QPainter(bmp)
        p.setRenderHint(QPainter.Antialiasing)
        p.setBrush(QBrush(Qt.white))
        p.setCompositionMode(QPainter.CompositionMode_Clear)
        p.drawRoundedRect(0, 0, self.width(), self.height(), 3, 3)
        p.end()
        self.setMask(QRegion(QBitmap(bmp))) 
Example 6
Project: IDArling   Author: IDArlingTeam   File: widget.py    License: GNU General Public License v3.0 4 votes vote down vote up
def paintEvent(self, event):  # noqa: N802
        """Called when the widget is being painted."""
        # Adjust the buffer size according to the pixel ratio
        dpr = self.devicePixelRatioF()
        buffer = QPixmap(self.width() * dpr, self.height() * dpr)
        buffer.setDevicePixelRatio(dpr)
        buffer.fill(Qt.transparent)

        painter = QPainter(buffer)

        # Paint the server text widget
        region = QRegion(
            QRect(QPoint(0, 0), self._servers_text_widget.sizeHint())
        )
        self._servers_text_widget.render(painter, QPoint(0, 0), region)
        # Paint the server icon widget
        region = QRegion(
            QRect(QPoint(0, 0), self._servers_icon_widget.sizeHint())
        )
        x = self._servers_text_widget.sizeHint().width() + 3
        self._servers_icon_widget.render(painter, QPoint(x, 0), region)
        # Paint the invites text widget
        region = QRegion(
            QRect(QPoint(0, 0), self._invites_text_widget.sizeHint())
        )
        x += self._servers_icon_widget.sizeHint().width() + 3
        self._invites_text_widget.render(painter, QPoint(x, 0), region)
        # Paint the invites icon widget
        region = QRegion(
            QRect(QPoint(0, 0), self._invites_icon_widget.sizeHint())
        )
        x += self._invites_text_widget.sizeHint().width() + 3
        self._invites_icon_widget.render(painter, QPoint(x, 0), region)
        # Paint the users text widget
        region = QRegion(
            QRect(QPoint(0, 0), self._users_text_widget.sizeHint())
        )
        x += self._invites_icon_widget.sizeHint().width() + 3
        self._users_text_widget.render(painter, QPoint(x, 0), region)
        # Paint the users icon widget
        region = QRegion(
            QRect(QPoint(0, 0), self._users_icon_widget.sizeHint())
        )
        x += self._users_text_widget.sizeHint().width() + 3
        self._users_icon_widget.render(painter, QPoint(x, 0), region)
        painter.end()

        painter = QPainter(self)
        painter.drawPixmap(event.rect(), buffer, buffer.rect())
        painter.end() 
Example 7
Project: backintime   Author: bit-team   File: qtsystrayicon.py    License: GNU General Public License v2.0 4 votes vote down vote up
def updateInfo(self):
        if not self.snapshots.busy():
            self.prepairExit()
            self.qapp.exit(0)
            return

        paused = tools.processPaused(self.snapshots.pid())
        self.btnPause.setVisible(not paused)
        self.btnResume.setVisible(paused)

        message = self.snapshots.takeSnapshotMessage()
        if message is None and self.last_message is None:
            message = (0, _('Working...'))

        if not message is None:
            if message != self.last_message:
                self.last_message = message
                if self.decode:
                    message = (message[0], self.decode.log(message[1]))
                self.menuStatusMessage.setText('\n'.join(tools.wrapLine(message[1],\
                                                                         size = 80,\
                                                                         delimiters = '',\
                                                                         new_line_indicator = '') \
                                                                       ))
                self.status_icon.setToolTip(message[1])

        pg = progress.ProgressFile(self.config)
        if pg.fileReadable():
            pg.load()
            percent = pg.intValue('percent')
            ## disable progressbar in icon until BiT has it's own icon
            ## fixes bug #902
            # if percent != self.progressBar.value():
            #     self.progressBar.setValue(percent)
            #     self.progressBar.render(self.pixmap, sourceRegion = QRegion(0, -14, 24, 6), flags = QWidget.RenderFlags(QWidget.DrawChildren))
            #     self.status_icon.setIcon(QIcon(self.pixmap))

            self.menuProgress.setText(' | '.join(self.getMenuProgress(pg)))
            self.menuProgress.setVisible(True)
        else:
            # self.status_icon.setIcon(self.icon.BIT_LOGO)
            self.menuProgress.setVisible(False)