Пример #1
0
 def sizeHint(self):
     fm = QFontMetrics(self.font())
     # FIXME: 暂时不是太懂应该怎样正确的计算 w 和 h
     # 计算 h 的一个原则是让高度正好能够显示一行
     h = max(fm.height() + fm.ascent() - fm.descent(), 14)
     w = self.width() - 4
     opt = QStyleOptionFrame()
     opt.initFrom(self)
     return self.style().sizeFromContents(
         QStyle.CT_LineEdit, opt,
         QSize(w, h).expandedTo(QApplication.globalStrut()), self)
Пример #2
0
 def sizeHint(self):
     fm = QFontMetrics(self.font())
     # FIXME: 暂时不是太懂应该怎样正确的计算 w 和 h
     # 计算 h 的一个原则是让高度正好能够显示一行
     h = max(fm.height() + fm.ascent() - fm.descent(), 14)
     w = self.width() - 4
     opt = QStyleOptionFrame()
     opt.initFrom(self)
     return self.style().sizeFromContents(
         QStyle.CT_LineEdit,
         opt,
         QSize(w, h).expandedTo(QApplication.globalStrut()),
         self
     )
Пример #3
0
    def paintEvent(self, _) -> None:
        p: QPainter = QPainter()
        p.begin(self)
        p.setRenderHint(QPainter.Antialiasing)

        panel: QStyleOptionFrame = QStyleOptionFrame()
        self.initStyleOption(panel)
        self.style().drawPrimitive(QStyle.PE_PanelLineEdit, panel, p, self)

        if self.cursor_is_visible():
            r = self.current_rect()
            txt_p = r.topLeft() + QPointF(TAG_TEXT_HORIZONTAL_PADDING, 4)

            # Draw the tags up to the current point where we are editing.
            self.draw_tags(p, 0, self.editing_index)

            # Draw the display text.
            p.setPen(QColor("#222"))
            formatting = self.formatting()
            self.text_layout.draw(p, txt_p, formatting)
            p.setPen(Qt.white)

            # Draw the cursor.
            if self.blink_status:
                self.text_layout.drawCursor(p, txt_p, self.cursor_ind)

            # Draw the tags after the cursor.
            self.draw_tags(p, self.editing_index + 1, len(self.tags))
        else:
            self.draw_tags(p, 0, len(self.tags))

        p.end()
Пример #4
0
    def setupUi(self):
        super(MainWindow, self).setupUi(self)

        self.search_box.shortcut = QShortcut(self.search_box)
        self.search_box.shortcut.setKey('Ctrl+F')

        self.output_devices_group = QActionGroup(self)
        self.input_devices_group = QActionGroup(self)
        self.alert_devices_group = QActionGroup(self)
        self.video_devices_group = QActionGroup(self)

        self.screen_sharing_button.addAction(QAction('Request screen', self.screen_sharing_button, triggered=self._AH_RequestScreenActionTriggered))
        self.screen_sharing_button.addAction(QAction('Share my screen', self.screen_sharing_button, triggered=self._AH_ShareMyScreenActionTriggered))

        # adjust search box height depending on theme as the value set in designer isn't suited for all themes
        search_box = self.search_box
        option = QStyleOptionFrame()
        search_box.initStyleOption(option)
        frame_width = search_box.style().pixelMetric(QStyle.PM_DefaultFrameWidth, option, search_box)
        if frame_width < 4:
            search_box.setMinimumHeight(20 + 2*frame_width)

        # adjust the combo boxes for themes with too much padding (like the default theme on Ubuntu 10.04)
        option = QStyleOptionComboBox()
        self.identity.initStyleOption(option)
        wide_padding = self.identity.style().subControlRect(QStyle.CC_ComboBox, option, QStyle.SC_ComboBoxEditField, self.identity).height() < 10
        self.identity.setStyleSheet("""QComboBox { padding: 0px 4px 0px 4px; }""" if wide_padding else "")
Пример #5
0
    def paintEvent(self, event):
        super(PromptLineEdit, self).paintEvent(event)

        qt_api = os.environ['QT_API'].lower()
        if self._prompt_text and not self.text() and self.isEnabled():
            if qt_api in PYQT4_API:
                from PyQt4.QtGui import QStyleOptionFrameV3
                option = QStyleOptionFrameV3()
            elif qt_api in PYSIDE_API:
                from PySide.QtGui import QStyleOptionFrameV3
                option = QStyleOptionFrameV3()
            elif qt_api in PYQT5_API:
                from PyQt5.QtWidgets import QStyleOptionFrame
                option = QStyleOptionFrame()
            else:
                msg = 'Qt bindings "%s" is not supported' % qt_api
                raise PythonQtError(msg)

            self.initStyleOption(option)

            left, top, right, bottom = self.getTextMargins()

            va = self.style().visualAlignment(self.layoutDirection(),
                                              self.alignment())
            rect = self.style().subElementRect(
                QtWidgets.QStyle.SE_LineEditContents, option,
                self).adjusted(2, 0, 0, 0).adjusted(left, top, -right, -bottom)
            fm = QtGui.QFontMetrics(self.font())
            text = fm.elidedText(self._prompt_text, QtCore.Qt.ElideRight,
                                 rect.width())
            painter = QtGui.QPainter(self)
            painter.setPen(self.palette().color(QtGui.QPalette.Disabled,
                                                QtGui.QPalette.Text))
            painter.drawText(rect, va, text)
Пример #6
0
    def paintEvent(self, evt):
        """
        Protected method handling a paint event.
        
        @param evt reference to the paint event (QPaintEvent)
        """
        super(E5LineEdit, self).paintEvent(evt)

        if qVersion() < "4.7.0":
            if not self.text() and \
               self.__inactiveText and \
               not self.hasFocus():
                panel = QStyleOptionFrame()
                self.initStyleOption(panel)
                textRect = self.style().subElementRect(
                    QStyle.SE_LineEditContents, panel, self)
                textRect.adjust(2, 0, 0, 0)
                left = self.textMargin(self.LeftSide)
                right = self.textMargin(self.RightSide)
                textRect.adjust(left, 0, -right, 0)
                painter = QPainter(self)
                painter.setPen(self.palette().brush(QPalette.Disabled,
                                                    QPalette.Text).color())
                painter.drawText(textRect, Qt.AlignLeft | Qt.AlignVCenter,
                                 self.__inactiveText)
Пример #7
0
 def paint(self, painter, rect):
     panel = QStyleOptionFrame()
     panel.initFrom(self)
     panel.lineWidth = 2
     panel.midLineWidth = 0
     panel.rect = panel.rect.adjusted(*self._margins)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Frame, panel, painter, self)
     rect = style.subElementRect(QStyle.SE_FrameContents, panel, self)
     painter.fillRect(rect, Qt.white)
     innerRect = rect.adjusted(2, 2, -2, -2)
     if self._color is not None:
         painter.fillRect(innerRect, self._color)
     else:
         pen = painter.pen()
         pen.setColor(strikeColor)
         pen.setWidthF(1.5)
         painter.setPen(pen)
         painter.setRenderHint(QStylePainter.Antialiasing)
         painter.setClipRect(innerRect)
         bL = innerRect.bottomLeft()
         bL.setY(bL.y() + .5)
         tR = innerRect.topRight()
         tR.setY(tR.y() + 1)
         painter.drawLine(bL, tR)
Пример #8
0
 def paintEvent(self, event):
     super().paintEvent(event)
     panel = QStyleOptionFrame()
     self.initStyleOption(panel)
     textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
     textRect.adjust(2, 0, -10, 0)
     painter = QPainter(self)
     painter.setPen(self.help_palette.brush(QPalette.Disabled, QPalette.Text).color())
     painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, "height")
Пример #9
0
 def paintEvent(self, event):
     super().paintEvent(event)
     panel = QStyleOptionFrame()
     self.initStyleOption(panel)
     textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
     textRect.adjust(2, 0, -10, 0)
     painter = QPainter(self)
     painter.setPen(ColorScheme.GRAY.as_color())
     painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, "height")
Пример #10
0
 def paintEvent(self, event):
     QLineEdit.paintEvent(self, event)
     if self.base_unit:
         panel = QStyleOptionFrame()
         self.initStyleOption(panel)
         textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
         textRect.adjust(2, 0, -10, 0)
         painter = QPainter(self)
         painter.setPen(ColorScheme.GRAY.as_color())  # NB: we hard-code gray here. It works ok for dark and light. FIXME: figure out why palette broke on Mojave dark mode see #1262
         painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, self.base_unit())
Пример #11
0
 def paintEvent(self, event):
     QLineEdit.paintEvent(self, event)
     if self.base_unit:
         panel = QStyleOptionFrame()
         self.initStyleOption(panel)
         textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
         textRect.adjust(2, 0, -10, 0)
         painter = QPainter(self)
         painter.setPen(QColor(ColorScheme.DEFAULT.as_color()))
         painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, self.base_unit())
Пример #12
0
 def paint(self, painter, rect):
     panel = QStyleOptionFrame()
     panel.initFrom(self)
     panel.lineWidth = 2
     panel.midLineWidth = 0
     panel.rect = panel.rect.adjusted(*self._margins)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Frame, panel, painter, self)
     rect = style.subElementRect(QStyle.SE_FrameContents, panel, self)
     painter.fillRect(rect, Qt.white)
     innerRect = rect.adjusted(2, 2, -2, -2)
     if self._color is not None:
         painter.fillRect(innerRect, self._color)
     else:
         pen = painter.pen()
         pen.setColor(strikeColor)
         pen.setWidthF(1.5)
         painter.setPen(pen)
         painter.setRenderHint(QStylePainter.Antialiasing)
         painter.setClipRect(innerRect)
         bL = innerRect.bottomLeft()
         bL.setY(bL.y() + .5)
         tR = innerRect.topRight()
         tR.setY(tR.y() + 1)
         painter.drawLine(bL, tR)
Пример #13
0
 def __init__(self, parent=None):
     super(LocationBar, self).__init__(parent=parent)
     self.clear_button = ClearButton(self)
     self.addTailWidget(self.clear_button)
     option = QStyleOptionFrame()
     self.initStyleOption(option)
     frame_width = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth,
                                            option, self)
     widgets_height = self.clear_button.minimumHeight()
     self.setMinimumHeight(widgets_height + 2 + 2 * frame_width)
     self.clear_button.hide()
     self.clear_button.clicked.connect(self._SH_ClearButtonClicked)
     self.textChanged.connect(self._SH_TextChanged)
Пример #14
0
 def paintEvent(self, event):
     ClearableEdit.paintEvent(self, event)
     if not bool(self.text()) and self.inactiveText and not self.hasFocus():
         panel = QStyleOptionFrame()
         self.initStyleOption(panel)
         text_rect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
         left_margin = 2
         right_margin = self._clearButton.iconSize().width()
         text_rect.adjust(left_margin, 0, -right_margin, 0)
         painter = QPainter(self)
         disabled_color = self.palette().brush(QPalette.Disabled, QPalette.Text).color()
         painter.setPen(disabled_color)
         painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter, self.inactiveText)
Пример #15
0
 def paintEvent(self, event):
     QLineEdit.paintEvent(self, event)
     if not self.hasFocus() and not self.text() and self.inactiveText:
         options = QStyleOptionFrame()
         self.initStyleOption(options)
         text_rect = self.style().subElementRect(QStyle.SE_LineEditContents,
                                                 options, self)
         text_rect.adjust(self.left_margin + 2, 0, -self.right_margin, 0)
         painter = QPainter(self)
         painter.setPen(self.palette().brush(QPalette.Disabled,
                                             QPalette.Text).color())
         painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter,
                          self.inactiveText)
Пример #16
0
 def paint(self, painter, rect):
     panel = QStyleOptionFrame()
     panel.initFrom(self)
     panel.lineWidth = 2
     panel.midLineWidth = 0
     panel.rect = panel.rect.adjusted(*self._margins)
     panel.state = panel.state | QStyle.State_Sunken
     self.style().drawPrimitive(QStyle.PE_Frame, panel, painter, self)
     r = self.style().subElementRect(QStyle.SE_FrameContents, panel, self)
     painter.fillRect(r, Qt.white)
     painter.fillRect(r.adjusted(2, 2, -2, -2), self._color)
Пример #17
0
    def paintEvent(self, pevent):
        painter = QPainter(self)

        if str(self.style().objectName()).lower() == "windowsxp":
            # WINDOWS XP IN CLASIC VIEW DISPLAYS NO GROUPFRAME
            styleoptions = QStyleOptionTabWidgetFrame()
            frame = QStyle.PE_FrameTabWidget

        else:
            styleoptions = QStyleOptionFrame()
            frame = QStyle.PE_FrameGroupBox

        styleoptions.initFrom(self)
        self.style().drawPrimitive(frame, styleoptions, painter, self)
Пример #18
0
 def __init__(self, parent=None):
     super(SearchBox, self).__init__(parent=parent)
     self.search_icon = SearchIcon(self)
     self.clear_button = ClearButton(self)
     self.addHeadWidget(self.search_icon)
     self.addTailWidget(self.clear_button)
     option = QStyleOptionFrame()
     self.initStyleOption(option)
     frame_width = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth,
                                            option, self)
     widgets_height = max(self.search_icon.minimumHeight(),
                          self.clear_button.minimumHeight())
     self.setMinimumHeight(widgets_height + 2 + 2 * frame_width)
     self.clear_button.hide()
     self.clear_button.clicked.connect(self.clear)
     self.textChanged.connect(self._SH_TextChanged)
     self.inactiveText = "Search"
Пример #19
0
 def _update_side_widget_locations(self):
     option = QStyleOptionFrame()
     self.initStyleOption(option)
     spacing = self.right_layout.spacing()
     text_rect = self.style().subElementRect(QStyle.SE_LineEditContents,
                                             option, self)
     text_rect.adjust(spacing, 0, -spacing, 0)
     mid_height = text_rect.center().y() + 1 - (
         text_rect.height() % 2)  # need -1 correction for odd heights -Dan
     if self.left_layout.count() > 0:
         left_height = int(mid_height - self.left_widget.height() / 2)
         left_width = self.left_widget.width()
         if left_width == 0:
             left_height = int(mid_height -
                               self.left_widget.sizeHint().height() / 2)
         self.left_widget.move(text_rect.x(), left_height)
     text_rect.setX(self.left_margin)
     text_rect.setY(
         int(mid_height - self.right_widget.sizeHint().height() / 2.0))
     text_rect.setHeight(self.right_widget.sizeHint().height())
     self.right_widget.setGeometry(text_rect)
Пример #20
0
 def __init__(self, parent=None):
     super(ValidatingLineEdit, self).__init__(parent)
     self.invalid_entry_label = QLabel(self)
     self.invalid_entry_label.setFixedSize(18, 16)
     self.invalid_entry_label.setPixmap(
         QPixmap(Resources.get('icons/invalid16.png')))
     self.invalid_entry_label.setScaledContents(False)
     self.invalid_entry_label.setAlignment(Qt.AlignCenter)
     self.invalid_entry_label.setObjectName('invalid_entry_label')
     self.invalid_entry_label.hide()
     self.addTailWidget(self.invalid_entry_label)
     option = QStyleOptionFrame()
     self.initStyleOption(option)
     frame_width = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth,
                                            option, self)
     self.setMinimumHeight(self.invalid_entry_label.minimumHeight() + 2 +
                           2 * frame_width)
     self.textChanged.connect(self._SH_TextChanged)
     self.text_correct = True
     self.text_allowed = True
     self.exceptions = set()
     self.regexp = re.compile(r'.*')
Пример #21
0
 def paint(self, painter, rect):
     panel = QStyleOptionFrame()
     self.initStyleOption(panel)
     style = self.style()
     # use PE_PanelLineEdit instead of static PE_Frame to have hover/focus
     # animation
     style.drawPrimitive(QStyle.PE_PanelLineEdit, panel, painter, self)
     rect = style.subElementRect(QStyle.SE_FrameContents, panel, self)
     painter.fillRect(rect, Qt.white)
     innerRect = rect.adjusted(2, 2, -2, -2)
     if self._color is not None:
         painter.fillRect(innerRect, self._color)
     else:
         pen = painter.pen()
         pen.setColor(strikeColor)
         pen.setWidthF(1.5)
         painter.setPen(pen)
         painter.setRenderHint(QStylePainter.Antialiasing)
         painter.setClipRect(innerRect)
         bL = innerRect.bottomLeft()
         bL.setY(bL.y() + .5)
         tR = innerRect.topRight()
         tR.setY(tR.y() + 1)
         painter.drawLine(bL, tR)
Пример #22
0
    def paintEvent(self, event):
        """QLineEdit.paintEvent implementation.
        Draws prompt
        """
        QLineEdit.paintEvent(self, event)

        if self._promptText and not self.text() and self.isEnabled():
            option = QStyleOptionFrame()
            self.initStyleOption(option)

            left, top, right, bottom = self.getTextMargins()

            va = self.style().visualAlignment(self.layoutDirection(),
                                              self.alignment())
            rect = self.style().subElementRect(
                QStyle.SE_LineEditContents, option,
                self).adjusted(2, 0, 0, 0).adjusted(left, top, -right, -bottom)
            fm = QFontMetrics(self.font())
            text = fm.elidedText(self._promptText, Qt.ElideRight, rect.width())
            painter = QPainter(self)

            painter.setPen(self.palette().color(QPalette.Disabled,
                                                QPalette.Text))
            painter.drawText(rect, va, text)
    def paintEvent(self, event: QPaintEvent) -> None:
        """
        Render the custom widget
        """

        painter = QStylePainter()
        painter.begin(self)

        x = 0
        y = 0
        width = self.width()

        rect = self.rect()  # type: QRect

        if self.display_type == DestinationDisplayType.usage_only and QSplitter(
        ).lineWidth():
            # Draw a frame if that's what the style requires
            option = QStyleOptionFrame()
            option.initFrom(self)
            painter.drawPrimitive(QStyle.PE_Frame, option)

            w = QSplitter().lineWidth()
            rect.adjust(w, w, -w, -w)

        palette = QPalette()
        backgroundColor = palette.base().color()
        painter.fillRect(rect, backgroundColor)

        if self.storage_space is None:
            painter.end()
            return

        highlight_menu = self.mouse_pos == DestinationDisplayMousePos.menu

        if self.display_type != DestinationDisplayType.usage_only:
            # Render the folder icon, folder name, and the menu icon
            self.deviceDisplay.paint_header(painter=painter,
                                            x=x,
                                            y=y,
                                            width=width,
                                            display_name=self.display_name,
                                            icon=self.icon,
                                            highlight_menu=highlight_menu)
            y = y + self.deviceDisplay.device_name_height

        if self.display_type != DestinationDisplayType.folder_only:
            # Render the projected storage space
            if self.display_type == DestinationDisplayType.usage_only:
                y += self.deviceDisplay.padding

            photos_size_to_download, videos_size_to_download = adjusted_download_size(
                photos_size_to_download=self.photos_size_to_download,
                videos_size_to_download=self.videos_size_to_download,
                os_stat_device=self.os_stat_device,
                downloading_to=self._downloading_to)

            details = make_body_details(
                bytes_total=self.storage_space.bytes_total,
                bytes_free=self.storage_space.bytes_free,
                files_to_display=self.files_to_display,
                marked=self.marked,
                photos_size_to_download=photos_size_to_download,
                videos_size_to_download=videos_size_to_download)

            self.deviceDisplay.paint_body(painter=painter,
                                          x=x,
                                          y=y,
                                          width=width,
                                          details=details)

        painter.end()
Пример #24
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     opt = QStyleOptionFrame()
     opt.initFrom(self)
     p.drawPrimitive(QStyle.PE_PanelTipLabel, opt)
     p.end()
Пример #25
0
    def paintEvent(self, event):

        if not self.customStyle:
            return QGroupBox.paintEvent(self, event)

        p = QStylePainter(self)
        opt = QStyleOptionGroupBox()
        self.initStyleOption(opt)

        style = qApp.style()
        groupBox = opt

        # // Draw frame
        textRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxLabel)
        checkBoxRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxCheckBox)

        p.save()
        titleRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame)
        # r.setBottom(style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxContents).top())
        titleRect.setHeight(textRect.height())
        titleRect.moveTop(textRect.top())

        p.setBrush(QBrush(QColor(Qt.blue).lighter(190)))
        p.setPen(Qt.NoPen)
        p.drawRoundedRect(titleRect, 10, 10)
        p.restore()

        if groupBox.subControls & QStyle.SC_GroupBoxFrame:
            frame = QStyleOptionFrame()
            # frame.operator=(groupBox)
            frame.state = groupBox.state
            frame.features = groupBox.features
            frame.lineWidth = groupBox.lineWidth
            frame.midLineWidth = groupBox.midLineWidth
            frame.rect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame)
            p.save()
            region = QRegion(groupBox.rect)
            if groupBox.text:
                ltr = groupBox.direction == Qt.LeftToRight
                finalRect = QRect()
                if groupBox.subControls & QStyle.SC_GroupBoxCheckBox:
                    finalRect = checkBoxRect.united(textRect)
                    finalRect.adjust(-4 if ltr else 0, 0, 0 if ltr else 4, 0)
                else:
                    finalRect = textRect

                region -= QRegion(finalRect)

            p.setClipRegion(region)
            style.drawPrimitive(style.PE_FrameGroupBox, frame, p)
            p.restore()

        # // Draw title
        if groupBox.subControls & QStyle.SC_GroupBoxLabel and groupBox.text:
            # textColor = QColor(groupBox.textColor)
            # if textColor.isValid():
            # p.setPen(textColor)
            # alignment = int(groupBox.textAlignment)
            # if not style.styleHint(QStyle.SH_UnderlineShortcut, opt):
            # alignment |= Qt.TextHideMnemonic

            # style.drawItemText(p, textRect,  Qt.TextShowMnemonic | Qt.AlignHCenter | alignment,
            # groupBox.palette, groupBox.state & style.State_Enabled, groupBox.text,
            # QPalette.NoRole if textColor.isValid() else QPalette.WindowText)

            p.save()
            topt = QTextOption(Qt.AlignHCenter | Qt.AlignVCenter)
            f = QFont()
            f.setBold(True)
            p.setFont(f)
            p.setPen(Qt.darkBlue)
            p.drawText(QRectF(titleRect), groupBox.text.replace("&", ""), topt)
            p.restore()

            if groupBox.state & style.State_HasFocus:
                fropt = QStyleOptionFocusRect()
                # fropt.operator=(groupBox)
                fropt.state = groupBox.state
                fropt.rect = textRect
                style.drawPrimitive(style.PE_FrameFocusRect, fropt, p)
 def paintEvent(self, *opts):
     painter = QStylePainter(self)
     option = QStyleOptionFrame()
     option.initFrom(self)
     painter.drawPrimitive(QStyle.PE_Frame, option)
     super().paintEvent(*opts)
Пример #27
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     opt = QStyleOptionFrame()
     opt.initFrom(self)
     p.drawPrimitive(QStyle.PE_PanelTipLabel, opt)
     p.end()
Пример #28
0
 def input_field_rect(self) -> QRectF:
     panel = QStyleOptionFrame()
     self.initStyleOption(panel)
     r = self.style().subElementRect(QStyle.SE_LineEditContents, panel,
                                     self)
     return r