예제 #1
0
    def show_top(self, widget, duration=2000):
        '''Show the notice at the top center of the specified widget'''

        ref_rect = widget.rect()
        ref_pos = QtCore.QPoint(int(ref_rect.width() * 0.5), ref_rect.top())
        ref_pos = widget.mapToGlobal(ref_pos)

        rect = self.rect()
        rect.setWidth(ref_rect.width())
        self.setGeometry(rect)

        pos = QtCore.QPoint(int(rect.width() * 0.5), rect.top())

        delta = ref_pos - pos
        self.move(delta)

        # Set start and end values for animation
        start_value = self.geometry()
        start_value.setHeight(0)
        end_value = self.geometry()

        self.show()

        anim = QtCore.QPropertyAnimation(
            self,
            QtCore.QByteArray('geometry'.encode()),
            parent=self,
        )
        anim.setDuration(150)
        anim.setEasingCurve(QtCore.QEasingCurve.OutQuad)
        anim.setStartValue(start_value)
        anim.setEndValue(end_value)
        anim.start()
        QtCore.QTimer.singleShot(duration, self._hide_top)
예제 #2
0
    def __move_to_systray(self):
        """ update the window position to be centered under the system tray icon """
        geo = self.systray.geometry()
        logger.debug("__move_to_systray: systray_geo: %s" % geo)

        side = self._guess_toolbar_side()

        if side == self.DOCK_TOP:
            x = geo.x() + (geo.width() - self.rect().width()) / 2.0
            pos = QtCore.QPoint(x, geo.y() + geo.height())
        elif side == self.DOCK_LEFT:
            y = geo.y() + (geo.height() - self.rect().height()) / 2.0
            pos = QtCore.QPoint(geo.x() + geo.width(), y)
        elif side == self.DOCK_RIGHT:
            y = geo.y() + (geo.height() - self.rect().height()) / 2.0
            pos = QtCore.QPoint(geo.x() - self.rect().width(), y)
        elif side == self.DOCK_BOTTOM:
            x = geo.x() + (geo.width() - self.geometry().width()) / 2.0
            pos = QtCore.QPoint(x,
                                geo.y() - self.rect().height() - geo.height())
        else:
            raise ValueError("Unknown value for side: %s" % side)

        # if part of the window will be drawn off screen, move the pos.
        screen_geometry = self._get_systray_screen_geometry()
        if (pos.x() + self.geometry().width()) > screen_geometry.right():
            diff = (pos.x() +
                    self.geometry().width()) - screen_geometry.right()
            pos = QtCore.QPoint(pos.x() - diff, pos.y())

        self.move(pos)

        if side != self.__class__:
            # anchor needs to be updated
            self._set_window_mask()
예제 #3
0
 def paintEvent(self, event):
     """
     Render the UI.
     """
     # first render the label
     QtGui.QLabel.paintEvent(self, event)
     
     if self.playable and self.interactive:
         # now render a pixmap on top
         painter = QtGui.QPainter()
         painter.begin(self)
         try:
             # set up semi transparent backdrop
             painter.setRenderHint(QtGui.QPainter.Antialiasing)
             
             # draw image
             painter.translate((painter.device().width() / 2) - (self._play_icon.width()/2), 
                               (painter.device().height() / 2) - (self._play_icon.height()/2) )
             
             if self._hover:
                 painter.drawPixmap( QtCore.QPoint(0, 0), self._play_icon)
             else:
                 painter.drawPixmap( QtCore.QPoint(0, 0), self._play_icon_inactive)
                 
         finally:
             painter.end()
예제 #4
0
    def drawObject(self, painter, rect, doc, pos_in_document, char_format):
        """Draw the appropriate widget based on the supplied char format."""

        # determine the bubble to draw
        bubble_id = char_format.property(self.BUBBLE_DATA_PROPERTY)
        bubble = self.get_bubble(bubble_id)
        bubble.setGeometry(rect.toRect())

        # now paint!
        painter.save()
        try:
            painter.translate(rect.topLeft().toPoint())

            # WEIRD! It seems pyside and pyqt actually have different signatures for this method
            if self.USING_PYQT:
                # pyqt is using the flags parameter, which seems inconsistent with QT
                # http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#render
                bubble.render(
                    painter,
                    QtCore.QPoint(0, 1),
                    QtGui.QRegion(),
                    QtGui.QWidget.DrawChildren,
                )
            else:
                # pyside is using the renderFlags parameter which seems correct
                bubble.render(
                    painter, QtCore.QPoint(0, 1), renderFlags=QtGui.QWidget.DrawChildren
                )
        finally:
            painter.restore()
    def indexAt(self, point):
        """
        Overriden base method that returns the model index under the specified point in
        the viewport

        :param point:   The QPoint to find the model index for
        :returns:       The model index for the item under the point or an invalid
                        QModelIndex() if there isn't one.
        """
        if not self.model():
            return QtCore.QModelIndex()

        # convert viewport relative point to global point:
        point = point + QtCore.QPoint(self.horizontalOffset(),
                                      self.verticalOffset())

        num_rows = len(self._item_info)
        if num_rows != self.model().rowCount():
            # just in case!
            return QtCore.QModelIndex()

        y_offset = self._border.height()
        for row, item_info in enumerate(self._item_info):

            # get point in local space:
            local_point = point + QtCore.QPoint(0, -y_offset)

            if local_point.y() < item_info.rect.y():
                # point definitely isn't on an item as we'd have found it by now!
                break

            # ok, we'll need an index for this row:
            index = self.model().index(row, 0)

            # check if the point is within this item:
            if item_info.rect.contains(local_point):
                return index

            # update y-offset:
            y_offset += item_info.rect.height()

            if not item_info.collapsed:
                # now check children:
                local_point = point + QtCore.QPoint(0, -y_offset)
                for child_row, (_, _,
                                child_rect) in enumerate(item_info.child_info):
                    if child_rect.contains(local_point):
                        # found a hit on a child item
                        return self.model().index(child_row, 0, index)

                # update y-offset
                y_offset += item_info.child_area_rect.height(
                ) + self._group_spacing
            else:
                y_offset += self._item_spacing.height()

        # no match so return invalid model index
        return QtCore.QModelIndex()
 def position_widget(self):
     """
     Place the widget just ouside the right corner of desktop
     Define the final position, in the top right corner of the desktop
     """
     desktop_rect = QtGui.QApplication.desktop().screenGeometry()
     self._start_pos = QtCore.QPoint((desktop_rect.width() - 10), 30)
     self._end_pos = self._start_pos - QtCore.QPoint(self.width(), 0)
     self.move(self._start_pos)
    def setAnim(self):

        self.setText()

        dist = self.rect().bottom()-self.rect().top()
        self.animate.setStartValue(QtCore.QPoint(0,self.rect().top() ))
        self.animate.setEndValue(QtCore.QPoint(0,self.rect().bottom() ))
        self.animate.setDuration(200*dist*self.speedFactor)
        self.animate.start()
예제 #8
0
    def paint(self, painter, style_options, model_index):
        """
        Paint method to handle all cells that are not being currently edited.

        :param painter:         The painter instance to use when painting
        :param style_options:   The style options to use when painting
        :param model_index:     The index in the data model that needs to be painted
        """

        # for performance reasons, we are not creating a widget every time
        # but merely moving the same widget around.
        paint_widget = self._get_painter_widget(model_index, self.parent())
        if not paint_widget:
            # just paint using the base implementation:
            QtGui.QStyledItemDelegate.paint(self, painter, style_options,
                                            model_index)
            return

        # make sure that the widget that is just used for painting isn't visible otherwise
        # it'll appear in the wrong place!
        paint_widget.setVisible(False)

        # call out to have the widget set the right values
        self._on_before_paint(paint_widget, model_index, style_options)

        # now paint!
        painter.save()
        try:
            paint_widget.resize(style_options.rect.size())
            painter.translate(style_options.rect.topLeft())
            # note that we set the render flags NOT to render the background of the widget
            # this makes it consistent with the way the editor widget is mounted inside
            # each element upon hover.

            # WEIRD! It seems pyside and pyqt actually have different signatures for this method
            if USING_PYQT:
                # pyqt is using the flags parameter, which seems inconsistent with QT
                # http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#render
                paint_widget.render(
                    painter,
                    QtCore.QPoint(0, 0),
                    QtGui.QRegion(),
                    QtGui.QWidget.DrawChildren,
                )
            else:
                # pyside is using the renderFlags parameter which seems correct
                paint_widget.render(painter,
                                    QtCore.QPoint(0, 0),
                                    renderFlags=QtGui.QWidget.DrawChildren)
        finally:
            painter.restore()
예제 #9
0
    def startDrag(self, event):
        index = self.indexAt(event.pos())
        if not index.isValid():
            return

        # selected is the relevant person object
        selected = self.model().data(index, QtCore.Qt.UserRole)
        logger.debug("Drag data: %s" % selected)
        # convert to a bytestream
        bstream = cPickle.dumps(selected)
        mimeData = QtCore.QMimeData()
        mimeData.setData("application/x-timelogevent", bstream)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)

        # the object itself
        pixmap = QtGui.QPixmap()
        pixmap = pixmap.grabWidget(self, self.rectForIndex(index))
        drag.setPixmap(pixmap)

        drag.setHotSpot(QtCore.QPoint(pixmap.width() / 2, pixmap.height() / 2))
        drag.setPixmap(pixmap)
        # pixmap = QtGui.QPixmap(100, self.height()/2)
        # pixmap.fill(QtGui.QColor("orange"))
        # drag.setPixmap(pixmap)

        result = drag.start(QtCore.Qt.MoveAction)
        if result:  # == QtCore.Qt.MoveAction:
            self.model().removeRow(index.row())
    def _get_loading_rect(self, option, index):
        """
        Override the base ViewItemDelegate method.

        Return the bounding rect for the item's loading icon. An invalid rect will be
        returned if the item is not in a loading state. The bounding rect will be positioned
        to the right in the option rect, and centered vertically.

        :param option: The option used for rendering the item.
        :type option: :class:`sgtk.platform.qt.QtGui.QStyleOptionViewItem`
        :param index: The index of the item.
        :type index: :class:`sgtk.platform.qt.QtCore.QModelIndex`

        :return: The bounding rect for the item's loading indicator. The rect will be invalid
                 if there is no loading indicatorto display.
        :rtype: :class:`sgtk.platform.qt.QtCore.QRect`
        """

        if not self.loading_role:
            return QtCore.QRect()

        loading = self.get_value(index, self.loading_role)
        if not loading:
            return QtCore.QRect()

        center = QtCore.QPoint(
            option.rect.left() + option.rect.width() / 2 -
            self.icon_size.width() / 2,
            option.rect.top() + option.rect.height() / 2 -
            self.icon_size.height() / 2,
        )

        return QtCore.QRect(center, self.icon_size)
예제 #11
0
    def resizeImage(self, image, newSize):
        if image.size() == newSize:
            return

        newImage = QtGui.QImage(newSize, QtGui.QImage.Format_RGB32)
        newImage.fill(QtGui.qRgb(255, 255, 255))
        painter = QtGui.QPainter(newImage)
        painter.drawImage(QtCore.QPoint(0, 0), image)

        self.image = newImage
예제 #12
0
 def add_attachment(self, pixmap):
     size = self.gridSize()
     item = QtGui.QListWidgetItem()
     item.attachment = pixmap
     pixmap = pixmap.scaled(
         size,
         QtCore.Qt.KeepAspectRatioByExpanding,
     ).copy(QtCore.QRect(QtCore.QPoint(), size))
     item.setIcon(QtGui.QIcon(pixmap))
     item.setSizeHint(size)
     self.insertItem(0, item)
     self._attachments.insert(0, item)
예제 #13
0
    def drawLineTo(self, endPoint):
        painter = QtGui.QPainter(self.image)
        painter.setPen(
            QtGui.QPen(self.myPenColor, self.myPenWidth, QtCore.Qt.SolidLine,
                       QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        painter.drawLine(self.lastPoint, endPoint)
        self.modified = True

        rad = self.myPenWidth / 2 + 2
        self.update(
            QtCore.QRect(self.lastPoint, endPoint).normalized().adjusted(
                -rad, -rad, +rad, +rad))
        self.lastPoint = QtCore.QPoint(endPoint)
예제 #14
0
    def __init__(self, parent=None):
        super(ScribbleArea, self).__init__(parent)

        self.setAttribute(QtCore.Qt.WA_StaticContents)
        self.modified = False
        self.scribbling = False
        self.myPenWidth = 3
        self.myPenColor = QtCore.Qt.red

        imageSize = QtCore.QSize(500, 500)

        self.image = QtGui.QImage(imageSize, QtGui.QImage.Format_RGB32)

        self.lastPoint = QtCore.QPoint()
예제 #15
0
    def eventFilter(self, object, event):
        """
        Attempts to identify clicks on one of the editor's bubble widget's
        remove button.

        :param object: The observed object.
        :type object: :class:`~PySide.QtCore.QObject`
        :param event: The event to filter.
        :type object: :class:`~PySide.QtCore.Qt.QEvent`
        :return: True'' if the event was filtered, ''False'' otherwise.
        """

        if not isinstance(event, QtGui.QMouseEvent):
            # only pass on mouse events
            return False

        # @todo:
        # can't seem to figure out how to map the viewport position to the
        # scroll area position. tried all combinations of mapto/from...
        # resulting to just adding the scroll values. please fix if you can
        edit_pos = QtCore.QPoint(
            event.pos().x() + self.horizontalScrollBar().value(),
            event.pos().y() + self.verticalScrollBar().value(),
        )

        # for mouse events find the actual widget at the position
        doc = self.document()
        cursor_pos = doc.documentLayout().hitTest(edit_pos, QtCore.Qt.ExactHit)
        char_format = doc.documentLayout().format(cursor_pos)
        bubble_id = char_format.property(
            _BubbleTextObject.BUBBLE_DATA_PROPERTY)
        bubble = self.get_bubble(bubble_id)

        if bubble is None:
            self.viewport().setCursor(QtCore.Qt.IBeamCursor)
            return False

        self.viewport().setCursor(QtCore.Qt.ArrowCursor)

        if event.type() == QtCore.QEvent.MouseButtonPress:
            # if we are clicking on the button, do so
            bubble_pos = bubble.mapFromParent(edit_pos)
            child_widget = bubble.childAt(bubble_pos)
            if isinstance(child_widget, QtGui.QPushButton):
                child_widget.click()
            return True

        return False
예제 #16
0
    def _on_popup_btn_click(self):
        """
        Handles displaying the popup menu when the button is clicked.
        """

        if self._editable:
            if self._pixmap:
                menu = self._popup_edit_menu
            else:
                menu = self._popup_upload_menu
        else:
            menu = self._popup_display_menu

        menu.exec_(
            self._popup_btn.mapToGlobal(
                QtCore.QPoint(0, self._popup_btn.height())))
    def _forward_mouse_event(self, mouse_event, index):
        """
        Forward the mouse event to the display widget to simulate
        interacting with the widget. This is necessary since the delegate only
        paints the widget in the view rather than being an actual widget
        instance.

        :param mouse_event: The event that occured on the delegate.
        :type mouse_event: :class:`~PySide.QtCore.QEvent`
        :param index: The model index that was acted on.
        :type index: :class:`~PySide.QtCore.QModelIndex`
        """

        # get the widget used to paint this index, populate it with the
        # value for this index
        widget = self._get_painter_widget(index, self.view)
        _set_widget_value(widget, index)

        item_rect = self.view.visualRect(index)

        # get the rect of the item in the view
        widget.resize(item_rect.size())

        # move the widget to 0, 0 so we know exactly where it is
        widget.move(0, 0)

        # map global mouse position to within item_rect
        view_pos = self.view.viewport().mapFromGlobal(QtGui.QCursor.pos())

        # calculate the offset from the item rect
        widget_x = view_pos.x() - item_rect.x()
        widget_y = view_pos.y() - item_rect.y()

        # forward the mouse event to the display widget
        forward_event = QtGui.QMouseEvent(
            mouse_event.type(),
            QtCore.QPoint(widget_x, widget_y),
            mouse_event.button(),
            mouse_event.buttons(),
            mouse_event.modifiers(),
        )
        QtGui.QApplication.sendEvent(widget, forward_event)
예제 #18
0
    def _on_popup_btn_click(self):
        """
        Display a context menu based on the current field value.
        """

        popup_menu = QtGui.QMenu()

        if self._value:
            link_type = self._value["link_type"]
        else:
            link_type = None

        if not link_type:
            # no link type, display options for each type
            popup_menu.addAction(self._upload_file_action)
            popup_menu.addAction(self._web_page_link_action)
            popup_menu.addAction(self._local_path_action)
        elif link_type == "upload":
            popup_menu.addAction(self._edit_upload_file_action)
            popup_menu.addAction(self._replace_with_web_page_link_action)
            popup_menu.addAction(self._replace_with_local_path_action)
            popup_menu.addAction(self._remove_link_action)
        elif link_type == "web":
            popup_menu.addAction(self._replace_with_upload_file_action)
            popup_menu.addAction(self._edit_web_page_link_action)
            popup_menu.addAction(self._replace_with_local_path_action)
            popup_menu.addAction(self._remove_link_action)
        elif link_type == "local":
            popup_menu.addAction(self._replace_with_upload_file_action)
            popup_menu.addAction(self._replace_with_web_page_link_action)
            popup_menu.addAction(self._edit_local_path_action)
            popup_menu.addAction(self._remove_link_action)

        # show the menu below the button
        popup_menu.exec_(
            self._popup_btn.mapToGlobal(
                QtCore.QPoint(0, self._popup_btn.height())
            )
        )
예제 #19
0
    def _set_window_mask(self):
        """ set the window mask when pinned to the systray """
        if self.state == self.STATE_WINDOWED:
            self.__content_layout.setContentsMargins(0, 0, 0, 0)
            self.clearMask()
            return

        # temp bitmap to store the mask
        bmp = QtGui.QBitmap(self.size())

        # create and configure the painter
        self.painter = QtGui.QPainter(bmp)
        self.painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing,
                                   True)

        # figure out what side to draw the anchor on
        side = self._guess_toolbar_side()

        # mask out from the top margin of the border_layout
        rect = self.rect()

        # make sure there is room to draw the anchor
        anchor_height = self.__bottom_anchor.height()
        if self.__content_layout is not None:
            if side == self.DOCK_TOP:
                mask = rect.adjusted(0, anchor_height, 0, 0)
                self.__content_layout.setContentsMargins(
                    0, anchor_height, 0, 0)
            elif side == self.DOCK_LEFT:
                mask = rect.adjusted(anchor_height, 0, 0, 0)
                self.__content_layout.setContentsMargins(
                    anchor_height, 0, 0, 0)
            elif side == self.DOCK_RIGHT:
                mask = rect.adjusted(0, 0, -anchor_height, 0)
                self.__content_layout.setContentsMargins(
                    0, 0, -anchor_height, 0)
            elif side == self.DOCK_BOTTOM:
                mask = rect.adjusted(0, 0, 0, -anchor_height)
                self.__content_layout.setContentsMargins(
                    0, 0, 0, anchor_height)
            else:
                raise ValueError("Unknown value for side: %s" % side)

        self.painter.fillRect(rect, QtCore.Qt.white)
        self.painter.setBrush(QtCore.Qt.black)
        self.painter.drawRoundedRect(mask, self.__corner_radius,
                                     self.__corner_radius)

        if self.state == self.STATE_PINNED:
            # add back in the anchor triangle
            points = []

            # make sure the triangle is drawn over the tray icon.
            rel_systray_geo_center = self.mapFromGlobal(
                self.systray.geometry().center())
            mask_center = QtCore.QPoint(rel_systray_geo_center.x(),
                                        mask.center().y())

            if side == self.DOCK_TOP:
                anchor_pixmap = self.__top_anchor
                points.append(QtCore.QPoint(mask_center.x(), rect.top()))
                points.append(
                    QtCore.QPoint(mask_center.x() - anchor_height, mask.top()))
                points.append(
                    QtCore.QPoint(mask_center.x() + anchor_height, mask.top()))
            elif side == self.DOCK_LEFT:
                anchor_pixmap = self.__left_anchor
                anchor_center = anchor_pixmap.rect().center()
                points.append(QtCore.QPoint(rect.left(), mask_center.y()))
                points.append(
                    QtCore.QPoint(mask.left(),
                                  mask_center.y() - anchor_center.y()))
                points.append(
                    QtCore.QPoint(mask.left(),
                                  mask_center.y() + anchor_center.y()))
            elif side == self.DOCK_RIGHT:
                anchor_pixmap = self.__right_anchor
                anchor_center = anchor_pixmap.rect().center()
                points.append(
                    QtCore.QPoint(mask.right(),
                                  mask_center.y() + anchor_center.y()))
                points.append(
                    QtCore.QPoint(mask.right(),
                                  mask_center.y() - anchor_center.y()))
                points.append(QtCore.QPoint(rect.right(), mask_center.y()))
            elif side == self.DOCK_BOTTOM:
                anchor_pixmap = self.__bottom_anchor
                anchor_center = anchor_pixmap.rect().center()
                points.append(
                    QtCore.QPoint(mask_center.x() - anchor_height,
                                  mask.bottom()))
                points.append(
                    QtCore.QPoint(mask_center.x() + anchor_height,
                                  mask.bottom()))
                points.append(QtCore.QPoint(mask_center.x(), rect.bottom()))
            else:
                raise ValueError("Unknown value for side: %s" % side)

            self.painter.drawPolygon(points)

        # need to end the painter to make sure that its resources get
        # garbage collected before the bitmap to avoid a crash
        self.painter.end()

        # finally set the window mask to the bitmap
        self.setMask(bmp)
        self.__anchor_side = side
예제 #20
0
    def paint(self, painter, style_options, model_index):
        """
        Paint method to handle all cells that are not being currently edited.

        :param painter:         The painter instance to use when painting
        :param style_options:   The style options to use when painting
        :param model_index:     The index in the data model that needs to be painted
        """
        sg_item = shotgun_model.get_sg_data(model_index)

        original_tn = model_index.data(self._ORIGINAL_THUMBNAIL)
        pinned_tn = model_index.data(self._PINNED_THUMBNAIL)
        filter_tn = model_index.data(self._FILTER_THUMBNAIL)

        # for performance reasons, we are not creating a widget every time
        # but merely moving the same widget around.
        paint_widget = self._get_painter_widget(model_index, self.parent())
        if not paint_widget:
            # just paint using the base implementation:
            QtGui.QStyledItemDelegate.paint(self, painter, style_options,
                                            model_index)
            return

        # make sure that the widget that is just used for painting isn't visible otherwise
        # it'll appear in the wrong place!
        paint_widget.setVisible(False)

        # call out to have the widget set the right values
        self._on_before_paint(paint_widget, model_index, style_options)

        # now paint!
        painter.save()
        try:
            paint_widget.resize(style_options.rect.size())
            painter.translate(style_options.rect.topLeft())
            # note that we set the render flags NOT to render the background of the widget
            # this makes it consistent with the way the editor widget is mounted inside
            # each element upon hover.

            paint_widget.render(painter,
                                QtCore.QPoint(0, 0),
                                renderFlags=QtGui.QWidget.DrawChildren)

            if self.tray_view.rv_mode.index_is_pinned(model_index.row()):
                painter.drawPixmap(
                    paint_widget.width() - self.pin_pixmap.width(), 0,
                    self.pin_pixmap)

            if not sg_item.get('version.Version.id') and not sg_item.get(
                    'image') and not sg_item.get(
                        'cut.Cut.version.Version.image'):
                target = QtCore.QRectF(0.0, 0.0, paint_widget.width(),
                                       paint_widget.height())
                source = QtCore.QRectF(0, 0, self.missing_pixmap.width(),
                                       self.missing_pixmap.height())
                # painter.drawPixmap(target, self.missing_pixmap, source)
                painter.fillRect(0, 0, paint_widget.width(),
                                 paint_widget.height(),
                                 QtGui.QColor(10, 0, 0, 255))
                painter.drawText(
                    0, 5, 100, 100,
                    QtCore.Qt.AlignHCenter | QtCore.Qt.AlignCenter, 'MISSING')

            mini_data = self.tray_view.rv_mode.cached_mini_cut_data

            if mini_data.active and painter:
                if mini_data.focus_clip == model_index.row():
                    painter.setPen(self._pen)
                    ws = paint_widget.size()
                    painter.drawRect(1, 1, ws.width() - 2, ws.height() - 2)

                if mini_data.first_clip > model_index.row(
                ) or mini_data.last_clip < model_index.row():
                    painter.fillRect(0, 0, paint_widget.width(),
                                     paint_widget.height(),
                                     QtGui.QColor(0, 0, 0, 220))

        finally:
            painter.restore()
예제 #21
0
 def paintEvent(self, event):
     painter = QtGui.QPainter(self)
     painter.drawImage(QtCore.QPoint(0, 0), self.image)
예제 #22
0
            def position_menu(self, horizontal, size_hint, toolbutton):
                """
                This method is copied from the C++ source qtoolbutton.cpp in Qt 5.15.1 fix version.
                :param horizontal: The orientation of the QToolBar that the menu is shown for. This
                should be True if the menu is not in a QToolBar.
                :param size_hint: The QSize size hint for this menu.
                :param toolbutton: The QToolButtonPatch object that this menu is shown for. Used to
                positiong the menu correctly.
                """

                point = QtCore.QPoint()

                rect = toolbutton.rect()
                desktop = QtGui.QApplication.desktop()
                screen = desktop.availableGeometry(
                    toolbutton.mapToGlobal(rect.center()))

                if horizontal:
                    if toolbutton.isRightToLeft():
                        if (toolbutton.mapToGlobal(
                                QtCore.QPoint(0, rect.bottom())).y() +
                                size_hint.height() <= screen.bottom()):
                            point = toolbutton.mapToGlobal(rect.bottomRight())

                        else:
                            point = toolbutton.mapToGlobal(
                                rect.topRight() -
                                QtCore.QPoint(0, size_hint.height()))

                        point.setX(point.x() - size_hint.width())

                    else:
                        if (toolbutton.mapToGlobal(
                                QtCore.QPoint(0, rect.bottom())).y() +
                                size_hint.height() <= screen.bottom()):
                            point = toolbutton.mapToGlobal(rect.bottomLeft())

                        else:
                            point = toolbutton.mapToGlobal(
                                rect.topLeft() -
                                QtCore.QPoint(0, size_hint.height()))

                else:
                    if toolbutton.isRightToLeft():

                        if (toolbutton.mapToGlobal(
                                QtCore.QPoint(rect.left(), 0)).x() -
                                size_hint.width() <= screen.x()):
                            point = toolbutton.mapToGlobal(rect.topRight())

                        else:
                            point = toolbutton.mapToGlobal(rect.topLeft())
                            point.setX(point.x() - size_hint.width())

                    else:
                        if (toolbutton.mapToGlobal(
                                QtCore.QPoint(rect.right(), 0)).x() +
                                size_hint.width() <= screen.right()):
                            point = toolbutton.mapToGlobal(rect.topRight())

                        else:
                            point = toolbutton.mapToGlobal(
                                rect.topLeft() -
                                QtCore.QPoint(size_hint.width(), 0))

                point.setX(
                    max(
                        screen.left(),
                        min(point.x(),
                            screen.right() - size_hint.width()),
                    ))
                point.setY(point.y() + 1)
                return point